在MongoDB中找到具有特定字段的所有集合?
让我们实现上述语法,以便在MongoDB中查找字段名称为“StudentFirstName”的所有文档。查询如下-
> db.getCollectionNames().forEach(function(myCollectionName) {
... var frequency = db[myCollectionName].find({"StudentFirstName": {$exists: true}}).count();
... if (frequency > 0) {
... print(myCollectionName);
... }
... });这将产生以下输出-
multiDimensionalArrayProjection removeKeyFieldsDemo stringOrIntegerQueryDemo
让我们验证removeKeyFieldsDemo集合是否具有名称为“StudentFirstName”的字段。以下是查询-
> db.removeKeyFieldsDemo.find({"StudentFirstName":{$exists:true}});这将产生以下输出,显示StudentFirstName字段存在-
{ "_id" : ObjectId("5cc6c8289cb58ca2b005e672"), "StudentFirstName" : "John", "StudentLastName" : "Doe" }
{ "_id" : ObjectId("5cc6c8359cb58ca2b005e673"), "StudentFirstName" : "John", "StudentLastName" : "Smith" }热门推荐
7 薛之谦祝福语简短
10 前程祝福语简短暖心
11 开业祝福语简短大气的
12 舅舅大婚文案祝福语简短
13 生日祝福语古朴简短独特
14 双十一祝福语大全简短
15 学生祝福语简短古诗句
16 中班入学祝福语简短大全
17 酒店客人祝福语简短
18 简短中秋祝福语朋友结婚