{"id":76221,"date":"2024-08-06T20:32:23","date_gmt":"2024-08-07T00:32:23","guid":{"rendered":"https:\/\/bangla.sitestree.com\/?p=76221"},"modified":"2024-08-06T20:32:33","modified_gmt":"2024-08-07T00:32:33","slug":"mongodb-lookup-and-aggregate-reference-model","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=76221","title":{"rendered":"MongoDB: Lookup and Aggregate: Reference Model"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>db.Reviews.drop();\n\ndb.Reviews.insertMany(&#91;\n \n    {_id:1, rating:5, comment: \"overall not bad\"},\n    {_id:2, rating:2, comment: \"overall not bad\"},\n    {_id:3, rating:3, comment: \"overall not bad\"},\n    {_id:4, rating:5, comment: \"overall not bad\"},\n    {_id:5, rating:4, comment: \"overall not bad\"},\n    {_id:6, rating:5, comment: \"overall not bad\"}\n \n]);  \n\ndb.ProductRefModel.drop(); \ndb.ProductRefModel.insertMany(&#91;\n    {\n        ProductId:1,\n        Description: \"Bottle\",\n        ReviewIds: &#91; 1, 2 ]\n    },\n    {\n        ProductId: 2,\n        Description: \"Air Pump\",\n        ReviewIds: &#91;3,4]\n    }\n    ]);\n    \n    \ndb.ProductRefModel.find();\n \ndb.ProductRefModel.aggregate(&#91;\n    {\n        $lookup: {\n            from: \"Reviews\",\n            localField: \"ReviewIds\",\n            foreignField: \"_id\",\n            as: \"Rating Details\"\n        }\n    }\n  ]\n); \n\n\ndb.Reviews.aggregate(&#91;\n    {\n        $lookup: {\n            from: \"ProductRefModel\",\n            localField: \"_id\",\n            foreignField: \"ReviewIds\",\n            as: \"Product Details\"\n        }\n    }\n  ]\n); \n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[182],"tags":[],"class_list":["post-76221","post","type-post","status-publish","format-standard","hentry","category---blog","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":76232,"url":"http:\/\/bangla.sitestree.com\/?p=76232","url_meta":{"origin":76221,"position":0},"title":"MongoDB: Insert, Collection, Aggregate, Lookup","author":"Sayed","date":"August 7, 2024","format":false,"excerpt":"db.orders.insertMany( [\u00a0 \u00a0{ \"_id\" : 1, \"item\" : \"almonds\", \"price\" : 12, \"quantity\" : 2 },\u00a0 \u00a0{ \"_id\" : 2, \"item\" : \"pecans\", \"price\" : 20, \"quantity\" : 1 },\u00a0 \u00a0{ \"_id\" : 3 \u00a0}] ) db.inventory.insertMany( [\u00a0 \u00a0{ \"_id\" : 1, \"sku\" : \"almonds\", \"description\": \"product 1\", \"instock\" :\u2026","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":6979,"url":"http:\/\/bangla.sitestree.com\/?p=6979","url_meta":{"origin":76221,"position":1},"title":"MongoDB Update Document","author":"Author-Check- Article-or-Video","date":"March 25, 2015","format":false,"excerpt":"MongoDB \u0986\u09aa\u09a1\u09c7\u099f \u09a1\u0995\u09c1\u09cd\u09ae\u09c7\u09a8\u09cd\u099f \u09a8\u09df\u09a8 \u099a\u09a8\u09cd\u09a6\u09cd\u09b0 \u09a6\u09a4\u09cd\u09a4 MongoDB \u098f\u09b0 update() \u098f\u09ac\u0982 save() \u09aa\u09a6\u09cd\u09a7\u09a4\u09bf \u098f\u0995\u099f\u09bf \u0995\u09be\u09b2\u09c7\u0995\u09b6\u09a8\u09c7 \u09a1\u0995\u09c1\u09ae\u09c7\u09a8\u09cd\u099f \u0986\u09aa\u09a1\u09c7\u099f \u0995\u09b0\u09a4\u09c7 \u09ac\u09cd\u09af\u09ac\u09b9\u09c3\u09a4 \u09b9\u09df\u0964 \u09af\u0996\u09a8 save() \u09aa\u09a6\u09cd\u09a7\u09a4\u09bf \u09ac\u09bf\u09a6\u09cd\u09af\u09ae\u09be\u09a8 \u09a8\u09a5\u09bf save() \u09aa\u09a6\u09cd\u09a7\u09a4\u09bf\u09cd\u09b0 \u09ae\u09a7\u09cd\u09af\u09c7 \u0997\u09c3\u09b9\u09c0\u09a4 \u09a1\u0995\u09c1\u09ae\u09c7\u09a8\u09cd\u099f \u09b8\u09be\u09a5\u09c7 \u09aa\u09cd\u09b0\u09a4\u09bf\u09b8\u09cd\u09a5\u09be\u09aa\u09a8 \u0995\u09b0\u09c7 \u09a4\u0996\u09a8 update() \u09aa\u09a6\u09cd\u09a7\u09a4\u09bf \u09ac\u09bf\u09a6\u09cd\u09af\u09ae\u09be\u09a8 \u09a1\u0995\u09c1\u09ae\u09c7\u09a8\u09cd\u099f \u098f\u09b0 value \u09ac\u09be \u09ae\u09be\u09a8\u0995\u09c7 \u0986\u09aa\u09a1\u09c7\u099f \u0995\u09b0\u09c7\u0964 MongoDB update() \u09aa\u09a6\u09cd\u09a7\u09a4\u09bf update() \u09aa\u09a6\u09cd\u09a7\u09a4\u09bf \u09ac\u09bf\u09a6\u09cd\u09af\u09ae\u09be\u09a8 \u09a1\u0995\u09c1\u09ae\u09c7\u09a8\u09cd\u099f\u09c7\u09b0\u2026","rel":"","context":"In &quot;Root&quot;","block_context":{"text":"Root","link":"http:\/\/bangla.sitestree.com\/?cat=1"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":76239,"url":"http:\/\/bangla.sitestree.com\/?p=76239","url_meta":{"origin":76221,"position":2},"title":"Shirt Collection and Mongo Queries","author":"Sayed","date":"August 7, 2024","format":false,"excerpt":"db.Shirts.remove({}); db.Shirts.insertMany( [ { Brand:\"Calvin\", Name: \"Name 1\", Color: [\"Blue\", \"Red\"], Price: 100, Size: { height:10, width:5 } }, { Brand:\"Tommy\", Name: \"Name 2\", Color: [\"Blue\", \"Red\", \"Orange\"], Price: 10, Size: { height:10, width:5 } } , { Brand:\"Calvin Kleins\", Name: \"Name 3\", Color: [\"Blue\", \"Red\", \"Orange\"], Price: 50, Size:\u2026","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":74659,"url":"http:\/\/bangla.sitestree.com\/?p=74659","url_meta":{"origin":76221,"position":3},"title":"Python and MongoDB Operations. Code Example","author":"Sayed","date":"May 17, 2022","format":false,"excerpt":"#!\/usr\/bin\/env python# coding: utf-8# In[63]: import pymongo; # In[64]: import pymongomyclient = pymongo.MongoClient(\"mongodb:\/\/localhost:27017\/\")mydb = myclient[\"mydatabase\"] # In[65]: # Check if database exist # In[66]: print(myclient.list_database_names()) # In[67]: dblist = myclient.list_database_names()if \"mydatabase\" in dblist:\u00a0 print(\"The database exists.\") # In[68]: # Create a collection # In[69]: import pymongomyclient = pymongo.MongoClient(\"mongodb:\/\/localhost:27017\/\")mydb = myclient[\"mydatabase\"]mycol\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"http:\/\/bangla.sitestree.com\/?cat=1428"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":6983,"url":"http:\/\/bangla.sitestree.com\/?p=6983","url_meta":{"origin":76221,"position":4},"title":"MongoDB Delete Document . MongoDB \u09a1\u09bf\u09b2\u09bf\u099f \u09a1\u0995\u09c1\u09ae\u09c7\u09a8\u09cd\u099f","author":"Author-Check- Article-or-Video","date":"March 6, 2015","format":false,"excerpt":"MongoDB \u09a1\u09bf\u09b2\u09bf\u099f \u09a1\u0995\u09c1\u09ae\u09c7\u09a8\u09cd\u099f \u09a8\u09df\u09a8 \u099a\u09a8\u09cd\u09a6\u09cd\u09b0 \u09a6\u09a4\u09cd\u09a4 remove() \u09aa\u09a6\u09cd\u09a7\u09a4\u09bf MongoDB \u098f\u09b0 remove() \u09aa\u09a6\u09cd\u09a7\u09a4\u09bf \u0995\u09be\u09b2\u09c7\u0995\u09b6\u09a8 \u09a5\u09c7\u0995\u09c7 \u09a1\u0995\u09c1\u09ae\u09c7\u09a8\u09cd\u099f \u09a1\u09bf\u09b2\u09bf\u099f \u0995\u09b0\u09a4\u09c7 \u09ac\u09cd\u09af\u09ac\u09b9\u09c3\u09a4 \u09b9\u09df\u0964 \u09a6\u09c1\u099f\u09bf \u09aa\u09cd\u09af\u09be\u09b0\u09be\u09ae\u09bf\u099f\u09be\u09b0 \u09ac\u09be\u09a6\u09c7 \u09b8\u09ac\u0995\u09cd\u09b7\u09c7\u09a4\u09cd\u09b0\u09c7 remove() \u09aa\u09a6\u09cd\u09a7\u09a4\u09bf \u0997\u09cd\u09b0\u09a3\u09af\u09cb\u0997\u09cd\u09af \u09b9\u09df\u0964 \u098f\u0995\u099f\u09bf deletion criteria \u098f\u09ac\u0982 \u0985\u09a8\u09cd\u09af\u099f\u09bf justOne flag \u0964 \u09e7\u0964 deletion criteria: (\u0985\u09aa\u09b6\u09a8\u09be\u09b2) \u09a1\u0995\u09c1\u09ae\u09c7\u09a8\u09cd\u099f \u0985\u09a8\u09c1\u09af\u09be\u09df\u09c0 deletion criteria \u09ae\u09c7\u099b\u09c7 \u09ab\u09c7\u09b2\u09be \u09b9\u09ac\u09c7\u0964 \u09e8\u0964 justOne: \u09af\u09a6\u09bf \u09b8\u09a4\u09cd\u09af\u2026","rel":"","context":"In &quot;\u09ae\u0999\u09cd\u0997 \u09a1\u09bf \u09ac\u09bf \u0964 MongoDB&quot;","block_context":{"text":"\u09ae\u0999\u09cd\u0997 \u09a1\u09bf \u09ac\u09bf \u0964 MongoDB","link":"http:\/\/bangla.sitestree.com\/?cat=222"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":6987,"url":"http:\/\/bangla.sitestree.com\/?p=6987","url_meta":{"origin":76221,"position":5},"title":"MongoDB Limit Records","author":"Author-Check- Article-or-Video","date":"April 24, 2015","format":false,"excerpt":"MongoDB \u09b8\u09c0\u09ae\u09be\u09ac\u09a6\u09cd\u09a7 \u09b0\u09c7\u0995\u09b0\u09cd\u09a1\u09b8 \u09a8\u09df\u09a8 \u099a\u09a8\u09cd\u09a6\u09cd\u09b0 \u09a6\u09a4\u09cd\u09a4 \u00a0 Limit() \u09aa\u09a6\u09cd\u09a7\u09a4\u09bf MongoDB \u09a4\u09c7 \u09b0\u09c7\u0995\u09b0\u09cd\u09a1\u0995\u09c7 \u09b8\u09c0\u09ae\u09be\u09ac\u09a6\u09cd\u09a7 \u0995\u09b0\u09a4\u09c7 \u09b9\u09b2\u09c7 limit() \u09ae\u09c7\u09a5\u09a1 \u09ac\u09be \u09aa\u09a6\u09cd\u09a7\u09a4\u09bf \u09ac\u09cd\u09af\u09ac\u09b9\u09be\u09b0 \u0995\u09b0\u09a4\u09c7 \u09b9\u09ac\u09c7\u0964 Limit() \u09aa\u09a6\u09cd\u09a7\u09a4\u09bf \u098f\u0995 \u09a8\u09be\u09ae\u09cd\u09ac\u09be\u09b0\u09c7\u09b0 \u099f\u09be\u0987\u09aa \u09b8\u09ae\u09b0\u09cd\u09a5\u09a8 \u0995\u09b0\u09c7 \u09af\u09be \u09a1\u0995\u09c1\u09ae\u09c7\u09a8\u09cd\u099f\u09c7\u09b0 \u09a8\u09be\u09ae\u09cd\u09ac\u09be\u09b0 \u098f\u09ac\u0982 \u0986\u09aa\u09a8\u09bf \u09aa\u09cd\u09b0\u09a6\u09b0\u09cd\u09b6\u09a8 \u0995\u09b0\u09a4\u09c7 \u099a\u09be\u0987\u099b\u09c7\u09a8\u0964 \u09b8\u09bf\u09a8\u099f\u09cd\u09af\u09be\u0995\u09cd\u09b8\u0983 limit() \u098f\u09b0 \u09ac\u09c7\u09b8\u09bf\u0995 \u09b8\u09bf\u09a8\u099f\u09cd\u09af\u09be\u0995\u09cd\u09b8 \u09a8\u09bf\u09ae\u09cd\u09a8\u09b0\u09c2\u09aa\u0983 >db.COLLECTION_NAME.find().limit(NUMBER) \u0989\u09a6\u09be\u09b9\u09b0\u09a3\u0983 \u09a8\u09bf\u09ae\u09cd\u09a8\u09b2\u09bf\u0996\u09bf\u09a4 \u09a4\u09a5\u09cd\u09af\u09c7\u09b0 \u09b8\u09be\u09a5\u09c7 myycol \u0995\u09be\u09b2\u09c7\u0995\u09b6\u09a8\u099f\u09bf\u2026","rel":"","context":"In &quot;Root&quot;","block_context":{"text":"Root","link":"http:\/\/bangla.sitestree.com\/?cat=1"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/76221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=76221"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/76221\/revisions"}],"predecessor-version":[{"id":76222,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/76221\/revisions\/76222"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=76221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=76221"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=76221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}