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" }