Welcome 微信登录

首页 / 数据库 / MySQL / MongoDB下的查询操作(与Java API查询操作对应)

相关阅读:MongoDB Linux下的安装和启动  http://www.linuxidc.com/Linux/2011-05/36309.htmMongoDB下的高级查询示例  http://www.linuxidc.com/Linux/2011-05/36312.htmMongoDB Java API for 插入和单collection基本查询使用示例 http://www.linuxidc.com/Linux/2011-05/36313.htmMongoDB下的查询操作(与Java API查询操作对应) http://www.linuxidc.com/Linux/2011-05/36314.htm[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" } }  
>   MongoDB Java API for 插入和单collection基本查询使用示例Linux下MySQL保存进去数据为乱码的解决办法相关资讯      MongoDB 
  • MongoDB 3.3.0 发布下载  (01月14日)
  • 使用MongoDB C#官方驱动操作  (12/31/2015 16:27:56)
  • CentOS 6.6下安装MongoDB 3.0.1  (12/21/2015 19:29:02)
  • MongoDB 3.2版WiredTiger存储引擎  (01月02日)
  • 进程监控工具Supervisor 启动  (12/26/2015 10:49:57)
  • MongoDB 3.2.1 RC0 发布下载  (12/18/2015 11:32:29)
本文评论 查看全部评论 (0)
表情: 姓名: 字数