[Mongo] MongoDB / Mongo Shell 指南

Intro

The mongo Shell – MongoDB Manual


安裝

Mac

$ brew tap mongodb/brew
$ brew install mongodb-community-shell

mongodb – Install mongo shell in mac – Stack Overflow

Compass. The GUI for MongoDB.

(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

MongoDB CRUD 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)

Leave a Reply

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