MongoDB之Linux通用二进制包安装(二)

2015-02-13 23:45:54 · 作者: · 浏览: 92
rnal file dbdata/journal/prealloc.2
2015-02-13T17:56:38.054+0800 [initandlisten]? ? ? ? File Preallocator Progress: 859832320/1073741824? ? 80%
2015-02-13T17:56:39.630+0800 [initandlisten] allocating new ns file dbdata/local.ns, filling with zeroes...
2015-02-13T17:56:39.762+0800 [FileAllocator] allocating new datafile dbdata/local.0, filling with zeroes...
2015-02-13T17:56:39.763+0800 [FileAllocator] creating directory dbdata/_tmp
2015-02-13T17:56:39.797+0800 [FileAllocator] done allocating datafile dbdata/local.0, size: 64MB,? took 0.002 secs
2015-02-13T17:56:39.832+0800 [initandlisten] build index on: local.startup_log properties: { v: 1, key: { _id: 1 }, name: "_id_", ns: "local.startup_log" }
2015-02-13T17:56:39.855+0800 [initandlisten]? ? ? added index to empty collection
2015-02-13T17:56:39.894+0800 [initandlisten] command local.$cmd command: create { create: "startup_log", size: 10485760, capped: true } ntoreturn:1 keyUpdates:0 numYields:0? reslen:37 281ms
2015-02-13T17:56:39.897+0800 [initandlisten] waiting for connections on port 27017


8
连接,简单使用
[root@linuxidc ~]# mongo
MongoDB shell version: 2.6.7
connecting to: test
#查看当前数据库
> db
test
#切到数据库 mydb
> use mydb
switched to db mydb
> db
mydb
#用java script创建两个文档
> 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/