आइए दस्तावेजों के साथ एक संग्रह बनाएं -
> db.demo675.insertOne({
... "ListOfNames":["John","Chris","David"]});
{
"acknowledged" : true,
"insertedId" : ObjectId("5ea3f5b404263e90dac943ef")
}
> db.demo675.insertOne({ "ListOfNames":["Bob","Johnson","Sam"]});
{
"acknowledged" : true,
"insertedId" : ObjectId("5ea3f5c804263e90dac943f0")
}
> db.demo675.insertOne({ "ListOfNames":["Jace","Sam"]});
{
"acknowledged" : true,
"insertedId" : ObjectId("5ea3f5d304263e90dac943f1")
} संग्रह से सभी दस्तावेज़ों को खोजने () विधि की सहायता से प्रदर्शित करें -
> db.demo675.find();
यह निम्नलिखित आउटपुट देगा -
{ "_id" : ObjectId("5ea3f5b404263e90dac943ef"), "ListOfNames" : [ "John", "Chris", "David" ] }
{ "_id" : ObjectId("5ea3f5c804263e90dac943f0"), "ListOfNames" : [ "Bob", "Johnson", "Sam" ] }
{ "_id" : ObjectId("5ea3f5d304263e90dac943f1"), "ListOfNames" : [ "Jace", "Sam" ] } निम्नलिखित रेगेक्सपी और सरणी के साथ क्वेरी करने के लिए है -
> db.demo675.find({"ListOfNames": {$in:[/John/,/J/]}}); यह निम्नलिखित आउटपुट देगा -
{ "_id" : ObjectId("5ea3f5b404263e90dac943ef"), "ListOfNames" : [ "John", "Chris", "David" ] }
{ "_id" : ObjectId("5ea3f5c804263e90dac943f0"), "ListOfNames" : [ "Bob", "Johnson", "Sam" ] }
{ "_id" : ObjectId("5ea3f5d304263e90dac943f1"), "ListOfNames" : [ "Jace", "Sam" ] }