Tag: MongoDB

  • How to Replace Characters in MongoDB

    TL; DR: As of MongoDB 6.0, this is how I learned to replace some characters in a field in all documents. In the example below all “.” characters in field_name will be replaced by “_” character: The backstory is when using MongoDB with MongoEngine, there’s an issue when a key in a dictionary field contains […]

  • How to Query in MongoDB and Group by Date

    TL;DR: Here’s a quick example to query MongoDB documents created this year(2023) and group them by date, ie. how many my_doc were created today, yesterday, the day before yesterday, etc. The following statement works in a MongoDB client such as mongosh. Then here’s an equivalent example to do it with MongoEngine in Python: Since I […]

  • Cheat Sheet: From SQL to NoSQL

    Recently I was fascinated by MongoDB’s flexibility to change data structure on the fly, in contrast there will need a ALT TABLE SQL statement for any schema change in a SQL database. Here I make a list of typical operations and how they are done in both SQL and NoSQL(in my case, MongoDB) flavours. Create […]