在mongodb中查找具有特定字段的所有集合 [英] Find all collections in mongodb with specific field
本文介绍了在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中查找具有特定字段的所有集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文