D:\MongoDB\mongodb-win32-i386-2.0.6\bin>mongo
MongoDB shell version: 2.0.6
connecting to: test
>
可以输入 help 获取帮忙信息。
D:\MongoDB\mongodb-win32-i386-2.0.6\bin>mongo
MongoDB shell version: 2.0.6
connecting to: test
> help
db.help() help on db methods
db.mycoll.help() help on collection methods
rs.help() help on replica set methods
help admin administrative help
help connect connecting to a db help
help keys key shortcuts
help misc misc things to know
help mr mapreduce
show dbs show database names
show collections show collections in current database
show users show users in current database
show profile show most recent system.profile entries wit
h time >= 1ms
show logs show the accessible logger names
show log [name] prints out the last segment of log in memor
y, 'global' is default
use set current database
db.foo.find() list objects in collection foo
db.foo.find( { a : 1 } ) list objects in foo where a == 1
it result of the last line evaluated; use to f
urther iterate
DBQuery.shellBatchSize = x set default number of items to display on s
hell
exit quit the mongo shell
> 1. 运行简单的数学运算
> db
foobar 一看是 foobar 是我们要使用的数据库
再用命令查看一下系统中所有的数据库
> show dbs
local (empty) 竟然没有,为什么呢?因为 只是创建了数据库 没有正在使用数据库 数据库MongoDB其实认为不存在,那我们进行存储数据吧
定义一个post对象
> post={"title":"My Blog Post","content":"Here's my blog post.","date":new Date()} 回车后显示对象内容
{
"title" : "My Blog Post",
"content" : "Here's my blog post.",
"date" : ISODate("2012-06-15T09:22:44.953Z")
} 将对象插入数据库中,看到下面插入之前,系统还认为不存在foobar数据库,插入后就能看到foobar数据库了。
> show dbs
local (empty)
> db
foobar
> db.blog.insert(post)
> show dbs
foobar 0.03125GB
local (empty)
> db
foobar find读取存储对象 find会返回集合中所有的文档 shell自动显示最多显示20个,可以继续获取更多进行查看更多文档。
> db.blog.find()
{ "_id" : ObjectId("4fdaff0b8f96acd2744b5086"), "title" : "My Blog Post", "conte
nt" : "Here's my blog post.", "date" : ISODate("2012-06-15T09:22:44.953Z") } findOne读取存储对象 findOne 只显示一个文档
> db.blog.findOne()
{
"_id" : ObjectId("4fdaff0b8f96acd2744b5086"),
"title" : "My Blog Post",
"content" : "Here's my blog post.",
"date" : ISODate("2012-06-15T09:22:44.953Z")
} find 和 findOne 可以带 查询条件 进行查询文档。