목록 필드에 대한 쿼리를 이해하거나 문서로 컬렉션을 만들 수 있습니다.
문서로 컬렉션을 생성하는 쿼리는 다음과 같습니다 -
> db.andOrDemo.insertOne({"StudentName":"Larry","StudentScore":[33,40,50,60,70]});
{
"acknowledged" : true,
"insertedId" : ObjectId("5c9522d316f542d757e2b444")
}
> db.andOrDemo.insertOne({"StudentName":"Larry","StudentScore":[87,67,79,98,90]});
{
"acknowledged" : true,
"insertedId" : ObjectId("5c95230916f542d757e2b445")
} find() 메서드를 사용하여 컬렉션의 모든 문서를 표시합니다. 쿼리는 다음과 같습니다 -
> db.andOrDemo.find().pretty();
다음은 출력입니다 -
{
"_id" : ObjectId("5c9522d316f542d757e2b444"),
"StudentName" : "Larry",
"StudentScore" : [
33,
40,
50,
60,
70
]
}
{
"_id" : ObjectId("5c95230916f542d757e2b445"),
"StudentName" : "Larry",
"StudentScore" : [
87,
67,
79,
98,
90
]
} 다음은 목록 필드에 대한 쿼리입니다.
쿼리는 다음과 같습니다 -
> db.andOrDemo.find({"StudentScore":70}).pretty(); 다음은 출력입니다.
{
"_id" : ObjectId("5c9522d316f542d757e2b444"),
"StudentName" : "Larry",
"StudentScore" : [
33,
40,
50,
60,
70
]
} 사례 3 − 다음은 또는 목록 필드에 대한 쿼리입니다.
쿼리는 다음과 같습니다 -
> db.andOrDemo.find({"$or":[ {"StudentScore":60}, {"StudentScore":90}]}).pretty(); 샘플 출력 -
{
"_id" : ObjectId("5c9522d316f542d757e2b444"),
"StudentName" : "Larry",
"StudentScore" : [
33,
40,
50,
60,
70
]
}
{
"_id" : ObjectId("5c95230916f542d757e2b445"),
"StudentName" : "Larry",
"StudentScore" : [
87,
67,
79,
98,
90
]
}