1

Mongo Hacker 不仅能够高亮 MongoDB Shell 的查询结果,还增强了查询语句。

mongo shell

安装方法

只要把 mongo_hacker.js 软链接到用户目录下的 .mongorc.js 就可以了(要求 MongoDB 2.2+,Windows 系统无法使用)。

手动安装:

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

自动安装:

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

可用扩展 API

Filter for a collection of documents:

db.collection.filter(<criteria>)

One for finding a single document:

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

Select for selecting fields to return (projection):

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

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

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

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

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

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

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()

皮拉帕拉
815 声望8 粉丝

人生就像DOTA,需要扎实的补刀、风骚的走位、必胜的欲望和永不放弃的心。