操作mongo db

 启动mongdb
 1 用root/root账号登录


 2 进入到/home/zxin10/mongodb/bin目录(执行 cd /home/zxin10/mongodb/bin)


 3 执行命令 nohup ./mongod --logpath /home/zxin10/mongodb/logs --dbpath /home/zxin10/mongodb/data/db --auth -directoryperdb &


 4 执行./mongo 连接mongoDB客户端,查看是否成功启动;出现
  connecting to: test
  >
  则表明启动成功。

注:非法操作数据库 /home/zxin10/mongodb/data/db 下有个 *.lock文件
    删掉,再重启tomcat。

 

(1)更新用户扩展信息:
db.user_basicinfo.update({"userid" : "1000000004"},{$set : {"status" : "0"}})
将当前userid的status改为1

(2)删除用户信息示例
db.user_basicinfo.remove({"userid" : "9999991"})
db.user_appinfo.remove({"userid" : "9999991"})

(3)新增用户信息示例
doc = { "email" : "[email protected]", "loginname" : "super", "mobilephone" : "18000000001", "servicelist" : [{ "SNS" : 1 }], "userid" : "9999991", "username" : "super", "userpwd" : "lY@BWzM_PD60D2LYiRxEJ3CfYcwcWcT8", "apid": "9000000001"}
db.user_basicinfo.insert(doc)
doc = {  "serviceid" : "SNS", "userid" : "9999991", "aptype" : "0", "websiteurl" : "http://zte.com.cn", "description" : "super....test",  "status" : "1", "regtime" : "2011-12-24 21:14:27" }
db.user_appinfo.insert(doc)

doc = {"test":"123","email" : "[email protected]", "loginname" : "super", "mobilephone" : "18000000001", "servicelist" : [{ "SNS" : 1 }], "userid" : "10000", "username" : "super", "userpwd" : "lY@BWzM_PD60D2LYiRxEJ3CfYcwcWcT8", "apid": "9000000001"}
db.user_basicinfo.insert(doc)

你可能感兴趣的:(mongo)