MongoDb Query

  • Show all collections: show collections
  • Show all document in collections: db.names.find()
  • Show all document in collections with pretty format: db.names.find().pretty()
  • Insert document into collection: db.names.insert({a:2})
  • Get all row with greater than and only show name and price column: db.products.find({price:{$gte:200}, {name:1, price: 1})
  • Querying: $gte, $in, $gt, $type, $lt, $lte, $or, $not, $nin (not in), $exists
  • Updating: $inc, $set, $addToSet
  • db.products.find().sort({lastname:1, firstname:1, postdate:-1}) //-1 is sort descending

Some MongoDb Query

Category: Uncategorized

Join the discussion

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