Intro
The mongo Shell – MongoDB Manual
安裝
Mac
$ brew tap mongodb/brew
$ brew install mongodb-community-shell
(TBC)
MongoDB Shell
The mongo Shell – MongoDB Manual
$ mango "mongodb://..."
> show dbs
> use {database}
> show collections
> db.{collection}.find()
> db.{collection}.find().pretty()
Query Operations
# Offset & Limit
> db.{colloection}.find().skip(20).limit(10)
> db.{colloection}.find({"key": "value"})
# regular expressions (similar to SQL LIKE)
> db.{colloection}.find({key: /alu/})
# Sorting (ASC vs DESC)
> db.{colloection}.find().sort(key: 1)
> db.{colloection}.find().sort(key: -1)