8
连接,简单使用
[root@linuxidc ~]# mongo
MongoDB shell version: 2.6.7
connecting to: test
#查看当前数据库
> db
test
#切到数据库 mydb
> use mydb
switched to db mydb
> db
mydb
#用Javascript创建两个文档
> j = { name : "mongo" }
{ "name" : "mongo" }
> k = { x : 3 }
{ "x" : 3 }
#创建mydb数据库和testdata collection
> db.testdata.insert(j)
WriteResult({ "nInserted" : 1 })
> db.testdata.insert(k);
WriteResult({ "nInserted" : 1 })
> show collections
system.indexes
testdata
> db.testdata.find()
{ "_id" : ObjectId("54ddd717d692cfe0bd20d983"), "name" : "mongo" }
{ "_id" : ObjectId("54ddd728d692cfe0bd20d984"), "x" : 3 }
>
>
> show dbs
admin (empty)
local 0.078GB
mydb 0.078GB
>
> use hahadb
switched to db hahadb
> show dbs
admin (empty)
local 0.078GB
mydb 0.078GB
> db
hahadb
> j = { name : "mongo" }
{ "name" : "mongo" }
> show dbs
admin (empty)
local 0.078GB
mydb 0.078GB
> db.testdata.insert(j)
WriteResult({ "nInserted" : 1 })
> show dbs
admin (empty)
hahadb 0.078GB
local 0.078GB
mydb 0.078GB
>
> use mydb
switched to db mydb
> show collections
system.indexes
testdata
>
> db.testdata.insert(j)
WriteResult({ "nInserted" : 1 })
> db.testdata.find()
{ "_id" : ObjectId("54ddd717d692cfe0bd20d983"), "name" : "mongo" }
{ "_id" : ObjectId("54ddd728d692cfe0bd20d984"), "x" : 3 }
{ "_id" : ObjectId("54ddda64d692cfe0bd20d986"), "name" : "mongo" }
> db.testdata.insert(k)
WriteResult({ "nInserted" : 1 })
>
>
> db.testdata.find()
{ "_id" : ObjectId("54ddd717d692cfe0bd20d983"), "name" : "mongo" }
{ "_id" : ObjectId("54ddd728d692cfe0bd20d984"), "x" : 3 }
{ "_id" : ObjectId("54ddda64d692cfe0bd20d986"), "name" : "mongo" }
{ "_id" : ObjectId("54ddda7dd692cfe0bd20d987"), "x" : 3 }
>
> db.testdata.find({x:3})
{ "_id" : ObjectId("54ddd728d692cfe0bd20d984"), "x" : 3 }
{ "_id" : ObjectId("54ddda7dd692cfe0bd20d987"), "x" : 3 }
>
>
> exit;
[root@linuxidc ~]#
参考:
docs.mongodb.org/manual/tutorial/install-mongodb-on-linux/
CentOS 6 使用 yum 安装MongoDB及服务器端配置
Ubuntu 13.04下安装MongoDB2.4.3
《MongoDB 权威指南》(MongoDB: The Definitive Guide)英文文字版[PDF]
基于CentOS 6.5操作系统搭建MongoDB服务 uxidc.com/Linux/2014-11/108900.htm