Skip to content

MongoDB

  • Reference: mongo shell quick reference
  • list all dbs in the mongo shell: show dbs
  • work with one db: use dbs
  • extracting the date from ObjectId:
 const date = new Date(parseInt(doc._id.substring(0, 8), 16) * 1000); 
 // new date object when this object created.
  • remove and element from a nested array:
   {
      $pull: {
        workshops: { _id: workshopId }
      }
    }

collection functions

  • collection.find() alaways need .toArray() after it.