gpt4 book ai didi

MongoDB 按属性名称搜索具有该属性的任何文档

转载 作者:IT老高 更新时间:2023-10-28 13:25:10 24 4
gpt4 key购买 nike

如何在 MongoDB 中搜索具有给定属性的任何文档?

我想要做的是找到所有具有该属性的文档,无论其值(value)如何,我似乎无法做到这一点。我已经尝试了以下

db.collection.find({"property", null}); //Finds things that don't have that property
db.collection.find({"proprety", {}}); //Doesn't find anything unless something has the empty object as the value

实际上是否有这样的语法或者我需要做一个 mapreduce 操作?

最佳答案

这是使用 $exists 的示例答案:

db.collection.find( { property : { $exists: true } } );

关于MongoDB 按属性名称搜索具有该属性的任何文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3857062/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com