MongoDB में सभी मानों का मिलान करने के लिए, $match के साथ $ और एकत्रीकरण का उपयोग करें। आइए दस्तावेजों के साथ एक संग्रह बनाएं -
> db.demo574.insertOne(
... {
... "details1": {
... "details2": {
... "dueDate": new ISODate("2020-01-10"),
... "Name": "Chris",
...
... "UserInformation": {
... "Name": "John",
... "Marks": 78
... },
... CountryName:"US"
... },
... id:101
... }
... }
... );
{
"acknowledged" : true,
"insertedId" : ObjectId("5e9167f3581e9acd78b427f6")
} संग्रह से सभी दस्तावेज़ों को खोजने () विधि की सहायता से प्रदर्शित करें -
> db.demo574.find();
यह निम्नलिखित आउटपुट देगा -
{
"_id" : ObjectId("5e9167f3581e9acd78b427f6"), "details1" :
{ "details2" : { "dueDate" : ISODate("2020-01-10T00:00:00Z"), "Name" : "Chris", "UserInformation" :
{ "Name" : "John", "Marks" : 78 }, "CountryName" : "US" }, "id" : 101 }
} एग्रीगेशन और मैच के साथ काम करने के लिए क्वेरी निम्नलिखित है -
> db.demo574.aggregate({
... $match: {
... $and: [
... {"details1.id": 101},
... {"details1.details2.UserInformation.Name": 'John'},
... {"details1.details2.Name": 'Chris'}
... ]
... }
... }
... ); यह निम्नलिखित आउटपुट देगा -
{
"_id" : ObjectId("5e9167f3581e9acd78b427f6"), "details1" :
{ "details2" : { "dueDate" : ISODate("2020-01-10T00:00:00Z"), "Name" : "Chris", "UserInformation" :
{ "Name" : "John", "Marks" : 78 }, "CountryName" : "US" }, "id" : 101 }
}