MongoDB Intro

  1. Connect to mongodb: $ mongo
  2. show dbs;
  3. db.<collection>.stats(1024000000) # gb – ref
  4. db.<collection>.find({},{<field>:<value>}).sort({<field>:1}).limit(5); # find top 5
  5. db.<collection>.find({},{<field>:1}).sort({<field>:-1}).limit(5); # find bottom 5
  6. db.<collection>.find({<field>:{ $lt: <val>}},{<field>:1}).count(); # count matches
  7. db.runCommand({compact:'<collection>’}) # compact collection

Leave a Reply

Your email address will not be published. Required fields are marked *