{"id":76688,"date":"2025-04-09T14:07:15","date_gmt":"2025-04-09T14:07:15","guid":{"rendered":"http:\/\/bangla.sitestree.com\/?p=76688"},"modified":"2025-04-09T14:07:15","modified_gmt":"2025-04-09T14:07:15","slug":"try-mongodb-regular-expresssions","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=76688","title":{"rendered":"Try: MongoDB Regular Expresssions"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>^ : starts with<\/p>\n\n\n\n<p>$ : Ends with<\/p>\n\n\n\n<p>.* : any char, any number of times<\/p>\n\n\n\n<p>\/i : case insensitive<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Try the following Queries<\/strong><\/p>\n\n\n\n<p>\u2022db.posts.find( { title: { $regex: \/4$\/ } } );<\/p>\n\n\n\n<p>\u2022db.posts.find( { category: { $regex: \/^T.*\/ } } );<\/p>\n\n\n\n<p>\u2022 db.posts.find( { category: { $not: \/^p.*\/ } } );<\/p>\n\n\n\n<p>\u2022db.posts.find( { category: { $regex: \/^ev\/i } } );<\/p>\n\n\n\n<p>\u2022db.posts.find( { category: { $regex: \/^ev\/ } } );<\/p>\n\n\n\n<p>\u2022db.posts.find( { category: { $regex: \/^Ev\/ } } );<\/p>\n\n\n\n<p>\u2022db.posts.find( { category: { $regex: \/^Ev.*t$\/ } } );<\/p>\n\n\n\n<p>\u2022db.posts.find( { category: { $regex: \/^Ev*t$\/ } } );<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Use Data from the Following URL:<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.w3schools.com\/mongodb\/mongodb_mongosh_insert.php\">https:\/\/www.w3schools.com\/mongodb\/mongodb_mongosh_insert.php<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>db.posts.insertMany(&#91;  \n  {\n    title: \"Post Title 2\",\n    body: \"Body of post.\",\n    category: \"Event\",\n    likes: 2,\n    tags: &#91;\"news\", \"events\"],\n    date: Date()\n  },\n  {\n    title: \"Post Title 3\",\n    body: \"Body of post.\",\n    category: \"Technology\",\n    likes: 3,\n    tags: &#91;\"news\", \"events\"],\n    date: Date()\n  },\n  {\n    title: \"Post Title 4\",\n    body: \"Body of post.\",\n    category: \"Event\",\n    likes: 4,\n    tags: &#91;\"news\", \"events\"],\n    date: Date()\n  }\n])<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>^ : starts with $ : Ends with .* : any char, any number of times \/i : case insensitive Try the following Queries \u2022db.posts.find( { title: { $regex: \/4$\/ } } ); \u2022db.posts.find( { category: { $regex: \/^T.*\/ } } ); \u2022 db.posts.find( { category: { $not: \/^p.*\/ } } ); \u2022db.posts.find( { category: &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=76688\">Continue reading<\/a><\/p>\n","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":[1],"tags":[],"class_list":["post-76688","post","type-post","status-publish","format-standard","hentry","category-root","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":76236,"url":"http:\/\/bangla.sitestree.com\/?p=76236","url_meta":{"origin":76688,"position":0},"title":"MongoDB: Shirts Colection, and Some Mongo Queries","author":"Sayed","date":"August 7, 2024","format":false,"excerpt":"db.Shirts.remove({}); db.Shirts.drop({}); 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,\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":76239,"url":"http:\/\/bangla.sitestree.com\/?p=76239","url_meta":{"origin":76688,"position":1},"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":76688,"position":2},"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":76690,"url":"http:\/\/bangla.sitestree.com\/?p=76690","url_meta":{"origin":76688,"position":3},"title":"MongoDB: Array Operations","author":"Sayed","date":"April 9, 2025","format":false,"excerpt":"Try these Array Operations: db.posts.find({}, {_id:0, category:1, tags:1}); db.posts.updateMany({category:'Event'}, {$addToSet:{tags:\"Tech\"}}); db.posts.updateMany({category:'Event'}, {$push:{tags:\"Tech Event\"}}); db.posts.updateMany({category:'Event'}, {$pull:{tags:\"Tech\"}}); db.posts.updateOne( { likes: 4 }, { $pop: { tags: -1 } } ) db.posts.updateMany({}, {$pull:{tags:[\"Tech\"]}}); db.posts.updateMany({}, {$pull:{tags:\"Tech\"}}); db.posts.updateMany({}, {$pull:{tags:{$in:[\"Tech\", \"Tech Event\"]}}}); Run it several times: db.posts.updateMany({}, {$push:{tags:\"Tech Event\"}}); Check data: db.posts.find({}, {tags:1, _id:0}); Pull and\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":22039,"url":"http:\/\/bangla.sitestree.com\/?p=22039","url_meta":{"origin":76688,"position":4},"title":"Must know for senior software developer positions. #Software Engineering","author":"Author-Check- Article-or-Video","date":"March 9, 2021","format":false,"excerpt":"Must know for senior software developer positions. What do you think? useful resources or not?Though not complete but can provide some ideas. What do you think?Developers planning to go to other software related roles may find the resources useful. what do you think?Business Analysishttp:\/\/justetc.net\/knowledge\/index.php?table=Articles&categoryID=66&category=Business%20AnalysisBusiness Curriculumhttp:\/\/justetc.net\/knowledge\/index.php?table=Articles&categoryID=67&category=Business%20CurriculamDot Net Solution Architecturehttp:\/\/justetc.net\/knowledge\/index.php?table=Articles&categoryID=20&category=Dot%20Net%20Solution%20ArchitectureSoftware Usabilityhttp:\/\/justetc.net\/knowledge\/index.php?table=Articles&categoryID=62&category=Human%20Computer%20InteractionManagementhttp:\/\/justetc.net\/knowledge\/index.php?table=Articles&categoryID=51&category=ManagementProject Managementhttp:\/\/justetc.net\/knowledge\/index.php?table=Articles&categoryID=30&category=Project%20ManagementSoftware\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":7892,"url":"http:\/\/bangla.sitestree.com\/?p=7892","url_meta":{"origin":76688,"position":5},"title":"WordPress \u098f\u09b0 Blog site \u098f \u09af\u09a6\u09bf category \u09af\u09cb\u0997 \u0995\u09b0\u09a4\u09c7 \u099a\u09be\u0987 : How to add category in WordPress site","author":"Author-Check- Article-or-Video","date":"March 29, 2015","format":false,"excerpt":"Wordpress \u098f\u09b0 Blogsite \u098f \u09af\u09a6\u09bf category \u09af\u09cb\u0997 \u0995\u09b0\u09a4\u09c7 \u099a\u09be\u0987, \u09a4\u09ac\u09c7 website \u098f \u09aa\u09cd\u09b0\u09a5\u09ae\u09c7 login \u0995\u09b0\u09a4\u09c7 \u09b9\u09ac\u09c7\u0964 \u098f\u09b0\u09aa\u09b0 \u09a6\u09c7\u0996\u09be \u09af\u09be\u09ac\u09c7 \u09b8\u09c7\u0996\u09be\u09a8\u09c7 \u0985\u09a8\u09c7\u0995\u0997\u09c1\u09b2\u09cb option \u09b0\u09df\u09c7\u099b\u09c7 , \u09af\u09be\u09b0 \u09ae\u09a7\u09cd\u09af \u09a5\u09c7\u0995\u09c7 dashboard \u0995\u09c7 select \u0995\u09b0\u09a4\u09c7 \u09b9\u09ac\u09c7\u0964 dashboard \u098f click \u0995\u09b0\u09be\u09b0 \u09aa\u09b0 \u09af\u09c7\u09b8\u09ac option \u0986\u09b8\u09ac\u09c7 \u09a4\u09be\u09b0 \u09ae\u09a7\u09cd\u09af \u09a5\u09c7\u0995\u09c7 category \u0995\u09c7 \u09ac\u09c7\u099b\u09c7 \u09a8\u09bf\u09a4\u09c7 \u09b9\u09ac\u09c7\u0964 category \u09a4\u09c7\u2026","rel":"","context":"In &quot;\u09a1\u099f \u09a8\u09c7\u099f\/.Net&quot;","block_context":{"text":"\u09a1\u099f \u09a8\u09c7\u099f\/.Net","link":"http:\/\/bangla.sitestree.com\/?cat=264"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/76688","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=76688"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/76688\/revisions"}],"predecessor-version":[{"id":76689,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/76688\/revisions\/76689"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=76688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=76688"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=76688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}