在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" }热门推荐
10 病人祝福语老师寄语简短
11 新娘生孩子祝福语简短
12 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短