如何查询 MongoDB 以测试项目是否存在? [英] How to query MongoDB to test if an item exists?

查看:10
本文介绍了如何查询 MongoDB 以测试项目是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MongoDB 是否提供查找或查询方法来根据任何字段值测试项目是否存在?我们只想检查是否存在,而不是返回项目的全部内容.

Does MongoDB offer a find or query method to test if an item exists based on any field value? We just want check existence, not return the full contents of the item.

推荐答案

我不相信有直接的方法可以通过项目的值来检查项目是否存在.但是你可以通过只检索 id (与字段选择)

I dont believe that there is a straight way of checking the existence of the item by its value. But you could do that by just retrieving only id (with field selection)

db.your_collection.find({..criteria..}, {"_id" : 1});

这篇关于如何查询 MongoDB 以测试项目是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆