Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Import a bson file into your Mongo /data/ folder: mongorestore -d db_name -c collection_name "C:\path\to\export.bson"
    • Make sure to add your MongoDB's 'bin' folder to the PATH to get mongorestore to work from a command prompt.
  • Run Mongod: "C:\Program Files\MongoDB\Server\4.0\bin\mongod.exe" --dbpath="c:\data\db"
  • Run MongoDB shell: "C:\Program Files\MongoDB\Server\4.0\bin\mongo.exe"
  • Show list of dbs: 'show dbs'
  • Switch to using a particular db: 'use <db>'
  • Show list of collections for the active db: 'show collections'
Queries
  • Get all records from a particular collection once you're switched to a particular db:
    • 'db.<collection_name>.find()'
  • Check if a field contains a string
    • db.getCollection('collection_name').find({"Party1": {$regex : ".*similarly situated.*"}})
  • Find records by non-existence of a field:
    • db.mycollection.find({ "price" : { "$exists" : false } })
  • Find a record by its id:
    • db.collection_name.find({"_id": ObjectId("587862a88362593254464c69")})
      • So you can find it by the id's string value, but you need to wrap the string with ObjectId()