Mongodb的默认端口号27017
_id是全局唯一值,不要去给这个列赋值,默认是唯一的,如果赋值,列入有两列的_id:2,则会报冲突不能插入
[[email protected] ~]# tar xvf mongodb-linux-x86_64-2.6.10.tgz
[[email protected] ~]# mkdir -p /export/mongodb
[[email protected] ~]# mkdir -p /export/mongodb/bin
[[email protected] ~]# mkdir -p /export/mongodb/conf
[[email protected] ~]# mkdir -p /export/mongodb/log
[[email protected]~]# mkdir -p /export/mongodb/data
[[email protected]]# cd /root/mongodb-linux-x86_64-2.6.10/bin
[[email protected]]# cp /root/mongodb-linux-x86_64-2.6.10/bin/* /export/mongodb/bin/
[[email protected]]# vi /export/mongodb/conf/mongod.conf
[[email protected]]# cat mongod.conf
port=27408
dbpath=/export/mongodb/data
logpath=/export/mongodb/log/mongod.log
fork=true
[[email protected]]# cd /export/mongodb/bin
[[email protected]]# ./mongod -f /export/mongodb/conf/mongod.conf
[[email protected]]# ./mongo --port 20011
>
>
> showdbs;
admin (empty)
local 0.078GB
> useadmin;
switchedto db admin
>db.shutdownServer()
[[email protected]]# netstat -anlp|grep mongod
[[email protected]]# ./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 }