점(.) 표기법을 사용하여 MongoDB 컬렉션에서 특정 키-값 쌍을 읽을 수 있습니다. 먼저 문서로 컬렉션을 생성해 보겠습니다. −
> db.readSpecificKeyValueDemo.insertOne(
... {
... "_id": 100,
... "StudentDetails":
... {
... "StudentFirstName" : "David",
... "StudentLastName" :"Miller",
... "StudentAge":23,
... "StudentCountryName":"US"
... }
... }
... );
{ "acknowledged" : true, "insertedId" : 100 } 다음은 find() 메서드를 사용하여 컬렉션의 모든 문서를 표시하는 쿼리입니다. -
> db.readSpecificKeyValueDemo.find().pretty();
이것은 다음과 같은 출력을 생성합니다 -
{
"_id" : 100,
"StudentDetails" : {
"StudentFirstName" : "David",
"StudentLastName" : "Miller",
"StudentAge" : 23,
"StudentCountryName" : "US"
}
} 다음은 MongoDB 컬렉션에서 특정 키-값 쌍을 읽는 쿼리입니다. −
> db.readSpecificKeyValueDemo.find({},{"StudentDetails.StudentCountryName":1}).pretty(); 이것은 다음과 같은 출력을 생성합니다 -
{ "_id" : 100, "StudentDetails" : { "StudentCountryName" : "US" } }