MongoDB使用

登录MongoDB
 
[root@oracle11g ~]# mongo
 
MongoDB shell version: 2.4.9
connecting to: test
 
> use admin
 
switched to db admin
 
> show dbs
 
admin   (empty)
local   0.078125GB
 
 
使用新的数据库my_mongodb
 
> use my_mongodb
 
switched to db my_mongodb
 
 
插入三条数据
 
> db.user.insert({uid:1,username:"Tom",age:25});
> db.user.insert({uid:2,username:"Jerry",age:25});
> db.user.insert({uid:1,username:"oracle",age:30});
 
向数据库my_mongodb的表user中插入了2条记录。MongoDB会隐式的创建数据库my_mongodb和表user
 
 
查看当前数据库
 
> show dbs
 
admin   (empty)
local   0.078125GB
my_mongodb      0.203125GB
 
 
查看当前连接
 
> show collections
 
system.indexes
user
 
 
查看user表中的数据
 
> db.user.find();
 
{ "_id" : ObjectId("55823677108162d31a1af236"), "uid" : 1, "username" : "Tom", "age" : 25 }
{ "_id" : ObjectId("55823696108162d31a1af237"), "uid" : 2, "username" : "Jerry", "age" : 25 }
{ "_id" : ObjectId("558236c0108162d31a1af238"), "uid" : 1, "username" : "oracle", "age" : 30 }
 
 
查找usernameJerry的数据
 
> db.user.find({username:"Jerry"});
 
{ "_id" : ObjectId("55823696108162d31a1af237"), "uid" : 2, "username" : "Jerry", "age" : 25 }
 
 
更新uid2age 100
 
> db.user.update({uid:2},{$set:{age:100}}) ;
 
 
检查数据是否更新成功
 
> db.user.find({uid:2});
 
{ "_id" : ObjectId("55823696108162d31a1af237"), "uid" : 2, "username" : "Jerry", "age" : 100 }
 

转载于:https://www.cnblogs.com/iyoume2008/p/9814624.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值