Mongodb的默认端口号27017
_id是全局唯一值,不要去给这个列赋值,默认是唯一的,如果赋值,列入有两列的_id:2,则会报冲突不能插入
[root@HE4 ~]# tar xvf mongodb-linux-x86_64-2.6.10.tgz
[root@HE4 ~]# mkdir -p /export/mongodb
[root@HE4 ~]# mkdir -p /export/mongodb/bin
[root@HE4 ~]# mkdir -p /export/mongodb/conf
[root@HE4 ~]# mkdir -p /export/mongodb/log
[root@HE4~]# mkdir -p /export/mongodb/data
[root@HE4bin]# cd /root/mongodb-linux-x86_64-2.6.10/bin
[root@HE4bin]# cp /root/mongodb-linux-x86_64-2.6.10/bin/* /export/mongodb/bin/
[root@HE4conf]# vi /export/mongodb/conf/mongod.conf
[root@HE4conf]# cat mongod.conf
port=27408
dbpath=/export/mongodb/data
logpath=/export/mongodb/log/mongod.log
fork=true
[root@HE4bin]# cd /export/mongodb/bin
[root@HE4bin]# ./mongod -f /export/mongodb/conf/mongod.conf
[root@HE4bin]# ./mongo --port 20011
>
>
> showdbs;
admin (empty)
local 0.078GB
> useadmin;
switchedto db admin
>db.shutdownServer()
[root@HE4bin]# netstat -anlp|grep mongod
[root@HE4bin]# ./mongo --port 20011
> usehelei;
switchedto db helei
>db.t1.insert({id:1})
WriteResult({"nInserted" : 1 })
>db.t1.insert({id:2});
WriteResult({"nInserted" : 1 })
>db.t1.find()
{"_id" : ObjectId("57033a5eade0255b255b4e22"),"id" : 1 }
{"_id" : ObjectId("57033a6bade0255b255b4e23"),"id" : 2 }
本文出自 “岁伏” 博客,请务必保留此出处http://suifu.blog.51cto.com/9167728/1789066