आइए पहले दस्तावेजों के साथ एक संग्रह बनाएं -
>db.demo144.insertOne({"EmployeeDetails":[{"EmployeeName":"Chris","EmployeeEmail":"[email protected]"},{"EmployeeName":"Bob","EmployeeEmail":"[email protected]"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e32f1d8fdf09dd6d08539b9") } >db.demo144.insertOne({"EmployeeDetails":[{"EmployeeName":"David","EmployeeEmail":"[email protected]"},{"EmployeeName":"Carol","EmployeeEmail":"[email protected]"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e32f1f5fdf09dd6d08539ba") }
संग्रह से सभी दस्तावेज़ों को खोजने () विधि की सहायता से प्रदर्शित करें -
> db.demo144.find();
यह निम्नलिखित आउटपुट देगा -
{ "_id" : ObjectId("5e32f1d8fdf09dd6d08539b9"), "EmployeeDetails" : [ { "EmployeeName" : "Chris", "EmployeeEmail" : "[email protected]" }, { "EmployeeName" : "Bob", "EmployeeEmail" : "[email protected]" } ] } { "_id" : ObjectId("5e32f1f5fdf09dd6d08539ba"), "EmployeeDetails" : [ { "EmployeeName" : "David", "EmployeeEmail" : "[email protected]" }, { "EmployeeName" : "Carol", "EmployeeEmail" : "[email protected]" } ] }
ऑब्जेक्ट्स की सरणी के भीतर परिणाम खोजने और ईमेल पता फ़ील्ड से मेल खाने के लिए क्वेरी निम्नलिखित है -
>db.demo144.find({"EmployeeDetails.EmployeeName":"David","EmployeeDetails.EmployeeEmail":"[email protected]"},{"EmployeeDetails.EmployeeName":1});
यह निम्नलिखित आउटपुट देगा -
{ "_id" : ObjectId("5e32f1f5fdf09dd6d08539ba"), "EmployeeDetails" : [ { "EmployeeName" : "David" }, { "EmployeeName" : "Carol" } ] }