Mongo Hacker - MongoDB 命令行配色加強工具

Mongo Hacker 不只可以高亮 MongoDB Shell 的查詢結果,還加強了查詢語句。git

mongo shell

安裝方法

只要把 mongo_hacker.js 軟連接到用戶目錄下的 .mongorc.js 就能夠了(要求 MongoDB 2.2+,Windows 系統沒法使用)。github

手動安裝:shell

$ git clone git@github.com:TylerBrock/mongo-hacker.git
$ cd mongo-hacker
$ ln -sf mongo_hacker.js ~/.mongorc.js

自動安裝:segmentfault

$ git clone git@github.com:TylerBrock/mongo-hacker.git
$ cd mongo-hacker
$ make

可用擴展 API

Filter for a collection of documents:bash

db.collection.filter(<criteria>)

One for finding a single document:spa

db.collection.find({ ... }).one() == db.collection.findOne({ ... })

Select for selecting fields to return (projection):code

db.collection.find({ ... }).select({ name: 1 })

Reverse for descending sort by insertion order (default) or arbitrary field:ip

db.collection.find({ ... }).reverse()
db.collection.find({ ... }).reverse('createDate')

Last for finding last inserted document (default) or document last by given field:rem

db.collection.find({ ... }).last()
db.collection.find({ ... }).last('createDate')

Update, Replace, Upsert and Remove can be called on a DBQuery Object:get

db.collection.find({ ... }).update({ ... })  // multi update
db.collection.find({ ... }).replace({ ... }) // single replacement
db.collection.find({ ... }).upsert({ ... })  // single upsert
db.collection.find({ ... }).remove()         // multi remove

Sort, limit, and skip through multi updates and removes:

db.collection.find({ ... }).limit(7).update({ ... })
db.collection.find({ ... }).sort({ ... }).skip(1).limit(3).update({ ... })
db.collection.find({ ... }).limit(3).remove()
相關文章
相關標籤/搜索