在mongodb中查找具有特定字段的所有集合

编程入门 行业动态 更新时间:2024-10-27 03:33:46
本文介绍了在mongodb中查找具有特定字段的所有集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我当前正在处理的数据库中有40多个集合. 所有收藏中的主要关键之一是帐户". 我需要知道所有这样的集合,其中有一个名为帐户"的字段.

There is more than 40 collections in database I am currently working on. One of the major key in all the collections is "account". I need to know all such collections where there is a field called "account".

是否有要获取的查询或打印所有此类集合的js脚本?

Is there a query to get or a js script which prints all such collections?

在Oracle中,我使用的是:

In Oracle I was using :

SELECT * FROM ALL_TAB_COLUMNS WHERE COLUMN_NAME LIKE 'account';

任何输入都是有帮助的.

Any inputs is helpful.

谢谢.

推荐答案

以下mongo脚本将打印出所有集合名称,其中至少一个文档包含account字段.

The following mongo script will print out all collection names where at least one document contains an account field.

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

更多推荐

在mongodb中查找具有特定字段的所有集合

本文发布于:2023-11-29 22:12:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647775.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   mongodb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!