सूची फ़ील्ड पर क्वेरी को समझने के लिए, और/या, आप दस्तावेज़ों के साथ एक संग्रह बना सकते हैं।
दस्तावेज़ के साथ संग्रह बनाने की क्वेरी इस प्रकार है -
> 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")
} संग्रह से सभी दस्तावेज़ों को ढूँढें () विधि की सहायता से प्रदर्शित करें। क्वेरी इस प्रकार है -
> 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
]
}