Heim > Datenbank > MySQL-Tutorial > MongoDB下的查询操作(与Java API查询操作对应)

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-06-07 17:01:26
Original
1310 Leute haben es durchsucht

[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" } }  
>  

linux

Verwandte Etiketten:
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Aktuelle Ausgaben
Parameterverständnis von Mongodb
Aus 1970-01-01 08:00:00
0
0
0
Verwendung von Symfony2 Mongodb
Aus 1970-01-01 08:00:00
0
0
0
mongodb _id umbenennen
Aus 1970-01-01 08:00:00
0
0
0
MongoDB schließt Verbindung – Stapelüberlauf
Aus 1970-01-01 08:00:00
0
0
0
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage