mongodb 数据操作

Microsoft Windows [版本 6.3.9600]
(c) 2013 Microsoft Corporation。保留所有权利。

C:\Users\dell>d:

D:\>cd mongodb

D:\mongodb>cd bin

D:\mongodb\bin>mongo
MongoDB shell version: 3.2.7
connecting to: test
> show dbs
local  0.000GB
> use part9
switched to db part9
> show dbs
local  0.000GB
> db.users.insert("username":"liaojianguo");
2016-06-15T10:40:06.847+0800 E QUERY    [thread1] SyntaxError: missing ) after a
rgument list @(shell):1:26

> db.users.insert({"username":"liaojianguo"});
WriteResult({ "nInserted" : 1 })
> show dbs
local  0.000GB
part9  0.000GB
> show collections
users
> db.users.find()
{ "_id" : ObjectId("5760c029aca72f8ea456bdbb"), "username" : "liaojianguo" }
> db.users.insert({"username":"zhulongfeng","group":"reporter"})
WriteResult({ "nInserted" : 1 })
> db.users.find()
{ "_id" : ObjectId("5760c029aca72f8ea456bdbb"), "username" : "liaojianguo" }
{ "_id" : ObjectId("5760c100aca72f8ea456bdbc"), "username" : "zhulongfeng", "gro
up" : "reporter" }
> db.users.find().count()
2
> db.users.find({"username":"liaojianguo"})
{ "_id" : ObjectId("5760c029aca72f8ea456bdbb"), "username" : "liaojianguo" }
> db.users.update({"username":"zhulongfeng","group","haha"});
2016-06-15T10:48:50.812+0800 E QUERY    [thread1] SyntaxError: missing : after p
roperty id @(shell):1:49

> db.users.update({"username":"zhulongfeng","group":"haha"});
2016-06-15T10:48:57.674+0800 E QUERY    [thread1] Error: need an object :
DBCollection.prototype._parseUpdate@src/mongo/shell/collection.js:505:1
DBCollection.prototype.update@src/mongo/shell/collection.js:539:18
@(shell):1:1

> db.users.update({"username":"zhulongfeng"},{"group":"haha"});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.users.find()
{ "_id" : ObjectId("5760c029aca72f8ea456bdbb"), "username" : "liaojianguo" }
{ "_id" : ObjectId("5760c100aca72f8ea456bdbc"), "group" : "haha" }
> db.users.update({"username":"zhulongfeng"},{$set:{"group":"xixi"}});
WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })
> db.users.find()
{ "_id" : ObjectId("5760c029aca72f8ea456bdbb"), "username" : "liaojianguo" }
{ "_id" : ObjectId("5760c100aca72f8ea456bdbc"), "group" : "haha" }
> db.users.update({"username":"zhulongfeng"},{$set:{"group":"xixi"}});
WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })
> db.users.find()
{ "_id" : ObjectId("5760c029aca72f8ea456bdbb"), "username" : "liaojianguo" }
{ "_id" : ObjectId("5760c100aca72f8ea456bdbc"), "group" : "haha" }
> db.users.insert({"username":"zhulongyang","group":"haha"})
WriteResult({ "nInserted" : 1 })
> db.users.find()
{ "_id" : ObjectId("5760c029aca72f8ea456bdbb"), "username" : "liaojianguo" }
{ "_id" : ObjectId("5760c100aca72f8ea456bdbc"), "group" : "haha" }
{ "_id" : ObjectId("5760c3cbaca72f8ea456bdbd"), "username" : "zhulongyang", "gro
up" : "haha" }
> db.users.insert({"username":"zhulongfeng","group":"reporter"})
WriteResult({ "nInserted" : 1 })
> db.users.find()
{ "_id" : ObjectId("5760c029aca72f8ea456bdbb"), "username" : "liaojianguo" }
{ "_id" : ObjectId("5760c100aca72f8ea456bdbc"), "group" : "haha" }
{ "_id" : ObjectId("5760c3cbaca72f8ea456bdbd"), "username" : "zhulongyang", "gro
up" : "haha" }
{ "_id" : ObjectId("5760c405aca72f8ea456bdbe"), "username" : "zhulongfeng", "gro
up" : "reporter" }
> db.users.update({"username":"zhulongfeng"},{$set:{"group":"xixi"}});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.users.remove({"_id":" ObjectId("5760c100aca72f8ea456bdbc")"})
2016-06-15T11:00:30.667+0800 E QUERY    [thread1] SyntaxError: identifier starts
 immediately after numeric literal @(shell):1:35

> db.users.remove({"_id":ObjectId("5760c100aca72f8ea456bdbc")});
WriteResult({ "nRemoved" : 1 })
> db.users.find()
{ "_id" : ObjectId("5760c029aca72f8ea456bdbb"), "username" : "liaojianguo" }
{ "_id" : ObjectId("5760c3cbaca72f8ea456bdbd"), "username" : "zhulongyang", "gro
up" : "haha" }
{ "_id" : ObjectId("5760c405aca72f8ea456bdbe"), "username" : "zhulongfeng", "gro
up" : "xixi" }
>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值