在所有文件夹中搜索一个特定字段。 mongodb

发布于 2025-02-11 20:06:50 字数 248 浏览 2 评论 0原文

我在所有这些文件夹中的数据库中有一个名为“ last_updated”的字段。我想知道是否可以在所有这些文件夹中搜索该特定字段

”在此处输入图像说明”

I have a field called "last_updated" in the database amongst all of those folders. I'm wondering if it is possible to search for that specific field in all those folders

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

给妤﹃绝世温柔 2025-02-18 20:06:51

如果您的意思是“集合”,这就是您可以做的:

db.getCollectionNames().forEach(function(collname) {
  var count = db[collname].find({"last_update": {$exists: true}}).limit(1);
  if (count > 0) {
  print(collname);
}
})

结果,您将拥有所有收集名称,其中至少有一个文档,其中一个文档具有LAST_UPDATE字段。

If by "folders" you mean "collections" , this is what you can do:

db.getCollectionNames().forEach(function(collname) {
  var count = db[collname].find({"last_update": {$exists: true}}).limit(1);
  if (count > 0) {
  print(collname);
}
})

As a result you will have all collection names where you have at least one document having last_update field present.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文