특정 속성을 기반으로 개체 목록을 표시하려면 find()에서 점 표기법을 사용하십시오. 문서로 컬렉션을 만들자 −
> db.demo455.insertOne({"Information":{"Student":[{"Name":"Chris","Age":22}]}});{
"acknowledged" : true,
"insertedId" : ObjectId("5e7e1876dbcb9adb296c95c5")
}
> db.demo455.insertOne({"Information":{"Student":[{"Name":"David","Age":21}]}});{
"acknowledged" : true,
"insertedId" : ObjectId("5e7e1883dbcb9adb296c95c6")
}
> db.demo455.insertOne({"Information":{"Student":[{"Name":"Bob","Age":24}]}});{
"acknowledged" : true,
"insertedId" : ObjectId("5e7e188adbcb9adb296c95c7")
}
> db.demo455.insertOne({"Information":{"Student":[{"Name":"Robert","Age":21}]}});{
"acknowledged" : true,
"insertedId" : ObjectId("5e7e18bcdbcb9adb296c95c8")
} find() 메서드를 사용하여 컬렉션의 모든 문서 표시 -
> db.demo455.find();
이것은 다음과 같은 출력을 생성합니다 -
{ "_id" : ObjectId("5e7e1876dbcb9adb296c95c5"), "Information" : { "Student" : [ { "Name" :
"Chris", "Age" : 22 } ] } }
{ "_id" : ObjectId("5e7e1883dbcb9adb296c95c6"), "Information" : { "Student" : [ { "Name" :
"David", "Age" : 21 } ] } }
{ "_id" : ObjectId("5e7e188adbcb9adb296c95c7"), "Information" : { "Student" : [ { "Name" :
"Bob", "Age" : 24 } ] } }
{ "_id" : ObjectId("5e7e18bcdbcb9adb296c95c8"), "Information" : { "Student" : [ { "Name" :
"Robert", "Age" : 21 } ] } } 다음은 특정 속성을 기반으로 개체 목록을 표시하는 쿼리입니다 -
> db.demo455.find({"Information.Student.Age":21}); 이것은 다음과 같은 출력을 생성합니다 -
{ "_id" : ObjectId("5e7e1883dbcb9adb296c95c6"), "Information" : { "Student" : [ { "Name" :
"David", "Age" : 21 } ] } }
{ "_id" : ObjectId("5e7e18bcdbcb9adb296c95c8"), "Information" : { "Student" : [ { "Name" :
"Robert", "Age" : 21 } ] } }