विशिष्ट फील्ड प्रदर्शित करने के लिए $project के साथ $unwind का उपयोग करें। किसी फील्ड को अनदेखा करने के लिए उसे 0 पर सेट करें। आइए एक कलेक्शन बनाते हैं:
> db.demo731.insertOne({ "ProductInformation": [ { ProductId:"Product-1", ProductPrice:80 }, { ProductId:"Product-2", ProductPrice:45 }, { ProductId:"Product-3", ProductPrice:50 } ] } ); { "acknowledged" : true, "insertedId" : ObjectId("5eac5efd56e85a39df5f6341") }
find() से सभी डॉक्यूमेंट्स देखें:
> db.demo731.find();
आउटपुट:
{ "_id" : ObjectId("5eac5efd56e85a39df5f6341"), "ProductInformation" : [ { "ProductId" : "Product-1", "ProductPrice" : 80 }, { "ProductId" : "Product-2", "ProductPrice" : 45 }, { "ProductId" : "Product-3", "ProductPrice" : 50 } ] }
MongoDB में $project का उपयोग करके सरणी में विशिष्ट फील्ड प्रदर्शित करने के लिए क्वेरी:
> db.demo731.aggregate([ ... { $unwind: "$ProductInformation" }, ... { $match: { "ProductInformation.ProductPrice": 80} }, ... { $project: {_id: 0,"ProductInformation.ProductPrice":0}} ... ])
परिणाम:
{ "ProductInformation" : { "ProductId" : "Product-1" } }