MongoDB সমষ্টিতে $sort ব্যবহার করুন। আসুন নথি-
সহ একটি সংগ্রহ তৈরি করি> db.demo652.insertOne({ ... value:10, ... "details" : [{ ... "ProductName" : "Product-1", ... "ProductQuantity" : 8, ... "ProductPrice" : 500 ... }, { ... "ProductName" : "Product-2", ... "ProductQuantity" : 7, ... "ProductPrice" : 500 ... ... }] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e9f0730e3c3cd0dcff36a62") } > > db.demo652.insertOne({ ... value:5, ... "details" : [{ ... "ProductName" : "Product-1", ... "ProductQuantity" : 8, ... "ProductPrice" : 500 ... }, { ... "ProductName" : "Product-2", ... "ProductQuantity" : 7, ... "ProductPrice" : 500 ... ... }] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e9f0740e3c3cd0dcff36a63") }
Find() পদ্ধতি -
এর সাহায্যে একটি সংগ্রহ থেকে সমস্ত নথি প্রদর্শন করুন> db.demo652.find();
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে{ "_id" : ObjectId("5e9f0730e3c3cd0dcff36a62"), "value" : 10, "details" : [ { "ProductName" : "Product-1", "ProductQuantity" : 8, "ProductPrice" : 500 }, { "ProductName" : "Product-2", "ProductQuantity" : 7, "ProductPrice" : 500 } ] } { "_id" : ObjectId("5e9f0740e3c3cd0dcff36a63"), "value" : 5, "details" : [ { "ProductName" : "Product-1", "ProductQuantity" : 8, "ProductPrice" : 500 }, { "ProductName" : "Product-2", "ProductQuantity" : 7, "ProductPrice" : 500 } ] }
−
ঊর্ধ্ব ক্রমানুসারে বাছাই করার জন্য নিচের প্রশ্নটি রয়েছে> db.demo652.aggregate([{ ... "$unwind": "$details" ... }, { ... "$match": {} ... }, { ... "$group": { ... "ProductPrice": { ... "$first": "$value" ... }, ... "details": { ... "$push": { ... "ProductName": "$details.ProductName" ... } ... }, ... "_id": "$_id" ... } ... }, { ... "$sort": { ... "ProductPrice": 1 ... } ... }, { ... "$project": { ... "_id": 0, ... "ProductPrice": 1, ... "details": 1 ... } ... }]).pretty()
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে{ "ProductPrice" : 5, "details" : [ { "ProductName" : "Product-1" }, { "ProductName" : "Product-2" } ] } { "ProductPrice" : 10, "details" : [ { "ProductName" : "Product-1" }, { "ProductName" : "Product-2" } ] }