java mongodb api 中文_MongoDB下的查询操作(与Java API查询操作对应)

[root@localhost ~]# mongo MongoDB shell version: 1.8.1 connecting to: test gt; db test gt; show collections

相关阅读:

MongoDB Linux下的安装和启动

MongoDB下的高级查询示例

MongoDB Java API for 插入和单collection基本查询使用示例

MongoDB下的查询操作(与Java API查询操作对应)

[root@localhost ~]# mongo

MongoDB shell version: 1.8.1

connecting to: test

> db

test

> show collections

data_test

system.indexes

system.users

> db.system.users.find()

{ "_id" : ObjectId("4dd73c7d247cb75e4995757b"), "user" : "iwtxokhtd", "readOnly" : false, "pwd" : "c728e00401a72282a2919648723dbff7" }

> db.data_test.find()

{ "_id" : ObjectId("4dd747cb3a491e68a1a84a30"), "userId" : "10010171", "userName" : "Bill Tu1", "gender" : "m1", "interests" : { "game" : "game1", "ball" : "ball1", "other" : "nothing1" } }

{ "_id" : ObjectId("4dd747cb3a491e68a1a84a31"), "userId" : "10010172", "userName" : "Bill Tu2", "gender" : "m2", "interests" : { "game" : "game2", "ball" : "ball2", "other" : "nothing2" } }

{ "_id" : ObjectId("4dd747cb3a491e68a1a84a32"), "userId" : "10010173", "userName" : "Bill Tu3", "gender" : "m3", "interests" : { "game" : "game3", "ball" : "ball3", "other" : "nothing3" } }

{ "_id" : ObjectId("4dd747cb3a491e68a1a84a33"), "userId" : "10010174", "userName" : "Bill Tu4", "gender" : "m4", "interests" : { "game" : "game4", "ball" : "ball4", "other" : "nothing4" } }

{ "_id" : ObjectId("4dd747cb3a491e68a1a84a34"), "userId" : "10010175", "userName" : "Bill Tu5", "gender" : "m5", "interests" : { "game" : "game5", "ball" : "ball5", "other" : "nothing5" } }

{ "_id" : ObjectId("4dd747cb3a491e68a1a84a35"), "userId" : "10010176", "userName" : "Bill Tu6", "gender" : "m6", "interests" : { "game" : "game6", "ball" : "ball6", "other" : "nothing6" } }

{ "_id" : ObjectId("4dd747cb3a491e68a1a84a36"), "userId" : "10010177", "userName" : "Bill Tu7", "gender" : "m7", "interests" : { "game" : "game7", "ball" : "ball7", "other" : "nothing7" } }

{ "_id" : ObjectId("4dd747cb3a491e68a1a84a37"), "userId" : "10010178", "userName" : "Bill Tu8", "gender" : "m8", "interests" : { "game" : "game8", "ball" : "ball8", "other" : "nothing8" } }

{ "_id" : ObjectId("4dd747cb3a491e68a1a84a38"), "userId" : "10010179", "userName" : "Bill Tu9", "gender" : "m9", "interests" : { "game" : "game9", "ball" : "ball9", "other" : "nothing9" } }

{ "_id" : ObjectId("4dd747cb3a491e68a1a84a39"), "userId" : "100101710", "userName" : "Bill Tu10", "gender" : "m10", "interests" : { "game" : "game10", "ball" : "ball10", "other" : "nothing10" } }

> db.data_test.findOne()

{

"_id" : ObjectId("4dd747cb3a491e68a1a84a30"),

"userId" : "10010171",

"userName" : "Bill Tu1",

"gender" : "m1",

"interests" : {

"game" : "game1",

"ball" : "ball1",

"other" : "nothing1"

}

}

> db.data_test.find({"userId":"10010171"})

{ "_id" : ObjectId("4dd747cb3a491e68a1a84a30"), "userId" : "10010171", "userName" : "Bill Tu1", "gender" : "m1", "interests" : { "game" : "game1", "ball" : "ball1", "other" : "nothing1" } }

> db.data_test.find({"userId":"10010171","userName":"Bill Tu1"})

{ "_id" : ObjectId("4dd747cb3a491e68a1a84a30"), "userId" : "10010171", "userName" : "Bill Tu1", "gender" : "m1", "interests" : { "game" : "game1", "ball" : "ball1", "other" : "nothing1" } }

> db.data_test.find({"userId":{$in:["10010171","10010172"]}})

{ "_id" : ObjectId("4dd747cb3a491e68a1a84a30"), "userId" : "10010171", "userName" : "Bill Tu1", "gender" : "m1", "interests" : { "game" : "game1", "ball" : "ball1", "other" : "nothing1" } }

{ "_id" : ObjectId("4dd747cb3a491e68a1a84a31"), "userId" : "10010172", "userName" : "Bill Tu2", "gender" : "m2", "interests" : { "game" : "game2", "ball" : "ball2", "other" : "nothing2" } }

> db.data_test.find({"userId":/10010171.*/i})

{ "_id" : ObjectId("4dd747cb3a491e68a1a84a30"), "userId" : "10010171", "userName" : "Bill Tu1", "gender" : "m1", "interests" : { "game" : "game1", "ball" : "ball1", "other" : "nothing1" } }

{ "_id" : ObjectId("4dd747cb3a491e68a1a84a39"), "userId" : "100101710", "userName" : "Bill Tu10", "gender" : "m10", "interests" : { "game" : "game10", "ball" : "ball10", "other" : "nothing10" } }

>

logo.gif

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值