无论该字段的值如何,如何使用MongoDB查找具有该字段的所有文档? [英] How can I use MongoDB to find all documents which have a field, regardless of the value of that field?

查看:68
本文介绍了无论该字段的值如何,如何使用MongoDB查找具有该字段的所有文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我收集了带有文档的文档,其中文档可以包含字段"url"(但大多数文档没有). 如何找到所有包含"url"字段的文档(无论此字段的值如何)?

For example, I have collection with documents, where documents can have field "url" (but most of them doesn't). How can I find all documents, which have field "url" (regardless of value of this field)?

推荐答案

要查找文档中是否存在键/字段,请使用

To find if a key/field exists in your document use the $exists operator.

通过MongoDB shell ...

Via the MongoDB shell ...

> db.things.find( { url : { $exists : true } } );

这篇关于无论该字段的值如何,如何使用MongoDB查找具有该字段的所有文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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