NoSQL Use Case Scenarios or WHEN to use NoSQL [closed]

It really is an “it depends” kinda question. Some general points: NoSQL is typically good for unstructured/”schemaless” data – usually, you don’t need to explicitly define your schema up front and can just include new fields without any ceremony NoSQL typically favours a denormalised schema due to no support for JOINs per the RDBMS world. … Read more

Filtering embedded documents in MongoDB

There’s currently no way to filter on embedded docs in the way you’re describing. Using the dot notation allows you to match on an embedded doc, but the entire document, parent and all, will still be returned. It’s also possible to select which fields will be returned, but that doesn’t really help your case, either. … Read more

MongoDB nested array query

After running some queries, I came to the conclusion that $in doesn’t work for an array of arrays. You can use $elemMatch instead and it’ll work, but it is frustrating that MongoDB’s documentation doesn’t warn about it. I created this document: { “_id”: “51cb12857124a215940cf2d4”, “level1”: [ [ “item00”, “item01” ], [ “item10”, “item11” ] ], … Read more

How to stop insertion of Duplicate documents in a mongodb collection

Don’t use insert. Use update with upsert=true. Update will look for the document that matches your query, then it will modify the fields you want and then, you can tell it upsert:True if you want to insert if no document matches your query. db.collection.update( <query>, <update>, { upsert: <boolean>, multi: <boolean>, writeConcern: <document> } ) … Read more

Fast or Bulk Upsert in pymongo

Modern releases of pymongo ( greater than 3.x ) wrap bulk operations in a consistent interface that downgrades where the server release does not support bulk operations. This is now consistent in MongoDB officially supported drivers. So the preferred method for coding is to use bulk_write() instead, where you use an UpdateOne other other appropriate … Read more