इसके लिए $exists ऑपरेटर का इस्तेमाल करें। आइए पहले दस्तावेजों के साथ एक संग्रह बनाएं -
>dbfindDocumentContainsSpecificFieldDemoinsertOne({"ProductPrices":{"Product1":10,"Pr oduct2":50}});
{
"acknowledged" : true,
"insertedId" : ObjectId("5cf2385bb64a577be5a2bc14")
}
>dbfindDocumentContainsSpecificFieldDemoinsertOne({"ProductPrices":{"Product3":150,"P roduct7":100,"Product5":250}});
{
"acknowledged" : true,
"insertedId" : ObjectId("5cf2387eb64a577be5a2bc15")
} खोज () विधि की मदद से संग्रह से सभी दस्तावेजों को प्रदर्शित करने के लिए क्वेरी निम्नलिखित है -
> dbfindDocumentContainsSpecificFieldDemofind()pretty();
यह निम्नलिखित दस्तावेज़ प्रस्तुत करेगा -
{
"_id" : ObjectId("5cf2385bb64a577be5a2bc14"),
"ProductPrices" : {
"Product1" : 10,
"Product2" : 50
}
}
{
"_id" : ObjectId("5cf2387eb64a577be5a2bc15"),
"ProductPrices" : {
"Product3" : 150,
"Product7" : 100,
"Product5" : 250
}
} विशिष्ट फ़ील्ड वाले दस्तावेज़ों को खोजने के लिए क्वेरी निम्नलिखित है -
> dbfindDocumentContainsSpecificFieldDemofind({"ProductPricesProduct2":{$exists:true}}); यह निम्नलिखित दस्तावेज़ प्रस्तुत करेगा -
{ "_id" : ObjectId("5cf2385bb64a577be5a2bc14"), "ProductPrices" : { "Product1" : 10, "Product2" : 50 } }