亚洲Aⅴ无码Av红楼在线观看_国产午夜福利涩爱AⅤ_国产sm调教一区二区三区_精品人妻一区二区三区不卡毛片

始創(chuàng)于2000年 股票代碼:831685
咨詢熱線:0371-60135900 注冊(cè)有禮 登錄
  • 掛牌上市企業(yè)
  • 60秒人工響應(yīng)
  • 99.99%連通率
  • 7*24h人工
  • 故障100倍補(bǔ)償
全部產(chǎn)品
您的位置: 網(wǎng)站首頁(yè) > 幫助中心>文章內(nèi)容

MongoDB下的高級(jí)查詢示例

發(fā)布時(shí)間:  2012/8/22 17:50:06

[root@localhost ~]# mongo  
MongoDB shell version: 1.8.1 
connecting to: test  
> db  
test  
> show collections  
data_test  
-
 

system.indexes  
system.users  
> db.data_test.find().skip(3).limit(4)//分頁(yè)查詢,從第4條記錄起,每頁(yè)4條。  
{ "_id" : ObjectId("4dd7c914b2d5f68db79cdf57"), "userId" : "10010174", "userName" : "Bill Tu4", "gender" : "m4", "interests" : { "game" : "game4", "ball" : "ball4",   
"other" : "nothing4" } }  
{ "_id" : ObjectId("4dd7c914b2d5f68db79cdf58"), "userId" : "10010175", "userName" : "Bill Tu5", "gender" : "m5", "interests" : { "game" : "game5", "ball" : "ball5",   
"other" : "nothing5" } }  
{ "_id" : ObjectId("4dd7c914b2d5f68db79cdf59"), "userId" : "10010176", "userName" : "Bill Tu6", "gender" : "m6", "interests" : { "game" : "game6", "ball" : "ball6",   
"other" : "nothing6" } }  
{ "_id" : ObjectId("4dd7c914b2d5f68db79cdf5a"), "userId" : "10010177", "userName" : "Bill Tu7", "gender" : "m7", "interests" : { "game" : "game7", "ball" : "ball7",   
"other" : "nothing7" } }  
> db.data_test.find({},{},4,3)//與上相同,注意此頁(yè)大小和起始位置的位置  
{ "_id" : ObjectId("4dd7c914b2d5f68db79cdf57"), "userId" : "10010174", "userName" : "Bill Tu4", "gender" : "m4", "interests" : { "game" : "game4", "ball" : "ball4",   
"other" : "nothing4" } }  
{ "_id" : ObjectId("4dd7c914b2d5f68db79cdf58"), "userId" : "10010175", "userName" : "Bill Tu5", "gender" : "m5", "interests" : { "game" : "game5", "ball" : "ball5",   
"other" : "nothing5" } }  
{ "_id" : ObjectId("4dd7c914b2d5f68db79cdf59"), "userId" : "10010176", "userName" : "Bill Tu6", "gender" : "m6", "interests" : { "game" : "game6", "ball" : "ball6",   
"other" : "nothing6" } }  
{ "_id" : ObjectId("4dd7c914b2d5f68db79cdf5a"), "userId" : "10010177", "userName" : "Bill Tu7", "gender" : "m7", "interests" : { "game" : "game7", "ball" : "ball7",   
"other" : "nothing7" } }  
> db.data_test.find().sort({"userName":-1})//order by:按userName倒序  
{ "_id" : ObjectId("4dd7c914b2d5f68db79cdf5c"), "userId" : "10010179", "userName" : "Bill Tu9", "gender" : "m9", "interests" : { "game" : "game9", "ball" : "ball9",   
"other" : "nothing9" } }  
{ "_id" : ObjectId("4dd7c914b2d5f68db79cdf5b"), "userId" : "10010178", "userName" : "Bill Tu8", "gender" : "m8", "interests" : { "game" : "game8", "ball" : "ball8",   
"other" : "nothing8" } }  
{ "_id" : ObjectId("4dd7c914b2d5f68db79cdf5a"), "userId" : "10010177", "userName" : "Bill Tu7", "gender" : "m7", "interests" : { "game" : "game7", "ball" : "ball7",   
"other" : "nothing7" } }  
{ "_id" : ObjectId("4dd7c914b2d5f68db79cdf59"), "userId" : "10010176", "userName" : "Bill Tu6", "gender" : "m6", "interests" : { "game" : "game6", "ball" : "ball6",   
"other" : "nothing6" } }  
{ "_id" : ObjectId("4dd7c914b2d5f68db79cdf58"), "userId" : "10010175", "userName" : "Bill Tu5", "gender" : "m5", "interests" : { "game" : "game5", "ball" : "ball5",   
"other" : "nothing5" } }  
{ "_id" : ObjectId("4dd7c914b2d5f68db79cdf57"), "userId" : "10010174", "userName" : "Bill Tu4", "gender" : "m4", "interests" : { "game" : "game4", "ball" : "ball4",   
"other" : "nothing4" } }  
{ "_id" : ObjectId("4dd7c914b2d5f68db79cdf56"), "userId" : "10010173", "userName" : "Bill Tu3", "gender" : "m3", "interests" : { "game" : "game3", "ball" : "ball3",   
"other" : "nothing3" } }  
{ "_id" : ObjectId("4dd7c914b2d5f68db79cdf55"), "userId" : "10010172", "userName" : "Bill Tu2", "gender" : "m2", "interests" : { "game" : "game2", "ball" : "ball2",   
"other" : "nothing2" } }  
{ "_id" : ObjectId("4dd7c914b2d5f68db79cdf5d"), "userId" : "100101710", "userName" : "Bill Tu10", "gender" : "m10", "interests" : { "game" : "game10", "ball" :   
"ball10", "other" : "nothing10" } }  
{ "_id" : ObjectId("4dd7c914b2d5f68db79cdf54"), "userId" : "10010171", "userName" : "Bill Tu1", "gender" : "m1", "interests" : { "game" : "game1", "ball" : "ball1",   
"other" : "nothing1" } }  
> db.data_test.find({"userName":{$ne:"Bill Tu10"},"age":{$gt:7}})//查詢userName!='Bill Tu10' and age>7  
{ "_id" : ObjectId("4dd7cf07b2d5f535b69b4128"), "userId" : "10010178", "userName" : "Bill Tu8", "gender" : "m8", "age" : 8, "interests" : { "game" : "game8", "ball" :   
"ball8", "other" : "nothing8" } }  
{ "_id" : ObjectId("4dd7cf07b2d5f535b69b4129"), "userId" : "10010179", "userName" : "Bill Tu9", "gender" : "m9", "age" : 9, "interests" : { "game" : "game9", "ball" :   
"ball9", "other" : "nothing9" } }  
> db.data_test.find({"age":{$gte:2},"age":{$lte:5}})//查詢age>=2 and age<=5  
{ "_id" : ObjectId("4dd7cf07b2d5f535b69b4121"), "userId" : "10010171", "userName" : "Bill Tu1", "gender" : "m1", "age" : 1, "interests" : { "game" : "game1", "ball" :   
"ball1", "other" : "nothing1" } }  
{ "_id" : ObjectId("4dd7cf07b2d5f535b69b4122"), "userId" : "10010172", "userName" : "Bill Tu2", "gender" : "m2", "age" : 2, "interests" : { "game" : "game2", "ball" :   
"ball2", "other" : "nothing2" } }  
{ "_id" : ObjectId("4dd7cf07b2d5f535b69b4123"), "userId" : "10010173", "userName" : "Bill Tu3", "gender" : "m3", "age" : 3, "interests" : { "game" : "game3", "ball" :   
"ball3", "other" : "nothing3" } }  
{ "_id" : ObjectId("4dd7cf07b2d5f535b69b4124"), "userId" : "10010174", "userName" : "Bill Tu4", "gender" : "m4", "age" : 4, "interests" : { "game" : "game4", "ball" :   
"ball4", "other" : "nothing4" } }  
{ "_id" : ObjectId("4dd7cf07b2d5f535b69b4125"), "userId" : "10010175", "userName" : "Bill Tu5", "gender" : "m5", "age" : 5, "interests" : { "game" : "game5", "ball" :   
"ball5", "other" : "nothing5" } }  
> db.data_test.find({"rank":{$all:[7,7]}})//查詢r(jià)ank=all(7,7)  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb98"), "userId" : "10010177", "userName" : "Bill Tu7", "gender" : "m7", "age" : 7, "rank" : [ 7, 7, 7 ], "interests" : {   
"game" : "game7", "ball" : "ball7", "other" : "nothing7" } }  
> db.data_test.find({"rank":{$all:[7,7,7]}})//查詢r(jià)ank=all(7,7,7)  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb98"), "userId" : "10010177", "userName" : "Bill Tu7", "gender" : "m7", "age" : 7, "rank" : [ 7, 7, 7 ], "interests" : {   
"game" : "game7", "ball" : "ball7", "other" : "nothing7" } }  
> db.data_test.find({"userName":{$exists:false}})  
> db.data_test.find({"age":{$mod:[2,0]}})//查詢age%2==0  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb93"), "userId" : "10010172", "userName" : "Bill Tu2", "gender" : "m2", "age" : 2, "rank" : [ 2, 2, 2 ], "interests" : {   
"game" : "game2", "ball" : "ball2", "other" : "nothing2" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb95"), "userId" : "10010174", "userName" : "Bill Tu4", "gender" : "m4", "age" : 4, "rank" : [ 4, 4, 4 ], "interests" : {   
"game" : "game4", "ball" : "ball4", "other" : "nothing4" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb97"), "userId" : "10010176", "userName" : "Bill Tu6", "gender" : "m6", "age" : 6, "rank" : [ 6, 6, 6 ], "interests" : {   
"game" : "game6", "ball" : "ball6", "other" : "nothing6" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb99"), "userId" : "10010178", "userName" : "Bill Tu8", "gender" : "m8", "age" : 8, "rank" : [ 8, 8, 8 ], "interests" : {   
"game" : "game8", "ball" : "ball8", "other" : "nothing8" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb9b"), "userId" : "100101710", "userName" : "Bill Tu10", "gender" : "m10", "age" : 10, "rank" : [ 10, 10, 10 ], "interests" :   
{ "game" : "game10", "ball" : "ball10", "other" : "nothing10" } }  
> db.data_test.find({"rank":{$in:[3,4]}})//查詢r(jià)ank in(3,4)  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb94"), "userId" : "10010173", "userName" : "Bill Tu3", "gender" : "m3", "age" : 3, "rank" : [ 3, 3, 3 ], "interests" : {   
"game" : "game3", "ball" : "ball3", "other" : "nothing3" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb95"), "userId" : "10010174", "userName" : "Bill Tu4", "gender" : "m4", "age" : 4, "rank" : [ 4, 4, 4 ], "interests" : {   
"game" : "game4", "ball" : "ball4", "other" : "nothing4" } }  
> db.data_test.find({"age":{$nin:[2,3]}})//查詢r(jià)ank not in(2,3)  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb92"), "userId" : "10010171", "userName" : "Bill Tu1", "gender" : "m1", "age" : 1, "rank" : [ 1, 1, 1 ], "interests" : {   
"game" : "game1", "ball" : "ball1", "other" : "nothing1" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb95"), "userId" : "10010174", "userName" : "Bill Tu4", "gender" : "m4", "age" : 4, "rank" : [ 4, 4, 4 ], "interests" : {   
"game" : "game4", "ball" : "ball4", "other" : "nothing4" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb96"), "userId" : "10010175", "userName" : "Bill Tu5", "gender" : "m5", "age" : 5, "rank" : [ 5, 5, 5 ], "interests" : {   
"game" : "game5", "ball" : "ball5", "other" : "nothing5" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb97"), "userId" : "10010176", "userName" : "Bill Tu6", "gender" : "m6", "age" : 6, "rank" : [ 6, 6, 6 ], "interests" : {   
"game" : "game6", "ball" : "ball6", "other" : "nothing6" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb98"), "userId" : "10010177", "userName" : "Bill Tu7", "gender" : "m7", "age" : 7, "rank" : [ 7, 7, 7 ], "interests" : {   
"game" : "game7", "ball" : "ball7", "other" : "nothing7" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb99"), "userId" : "10010178", "userName" : "Bill Tu8", "gender" : "m8", "age" : 8, "rank" : [ 8, 8, 8 ], "interests" : {   
"game" : "game8", "ball" : "ball8", "other" : "nothing8" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb9a"), "userId" : "10010179", "userName" : "Bill Tu9", "gender" : "m9", "age" : 9, "rank" : [ 9, 9, 9 ], "interests" : {   
"game" : "game9", "ball" : "ball9", "other" : "nothing9" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb9b"), "userId" : "100101710", "userName" : "Bill Tu10", "gender" : "m10", "age" : 10, "rank" : [ 10, 10, 10 ], "interests" :   
{ "game" : "game10", "ball" : "ball10", "other" : "nothing10" } }  
> db.data_test.find({$or:[{"age":{$gt:3}},{"rank":{$all:[1,1]}}]})//查詢age>3 or rank=all(1,1)  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb92"), "userId" : "10010171", "userName" : "Bill Tu1", "gender" : "m1", "age" : 1, "rank" : [ 1, 1, 1 ], "interests" : {   
"game" : "game1", "ball" : "ball1", "other" : "nothing1" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb95"), "userId" : "10010174", "userName" : "Bill Tu4", "gender" : "m4", "age" : 4, "rank" : [ 4, 4, 4 ], "interests" : {   
"game" : "game4", "ball" : "ball4", "other" : "nothing4" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb96"), "userId" : "10010175", "userName" : "Bill Tu5", "gender" : "m5", "age" : 5, "rank" : [ 5, 5, 5 ], "interests" : {   
"game" : "game5", "ball" : "ball5", "other" : "nothing5" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb97"), "userId" : "10010176", "userName" : "Bill Tu6", "gender" : "m6", "age" : 6, "rank" : [ 6, 6, 6 ], "interests" : {   
"game" : "game6", "ball" : "ball6", "other" : "nothing6" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb98"), "userId" : "10010177", "userName" : "Bill Tu7", "gender" : "m7", "age" : 7, "rank" : [ 7, 7, 7 ], "interests" : {   
"game" : "game7", "ball" : "ball7", "other" : "nothing7" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb99"), "userId" : "10010178", "userName" : "Bill Tu8", "gender" : "m8", "age" : 8, "rank" : [ 8, 8, 8 ], "interests" : {   
"game" : "game8", "ball" : "ball8", "other" : "nothing8" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb9a"), "userId" : "10010179", "userName" : "Bill Tu9", "gender" : "m9", "age" : 9, "rank" : [ 9, 9, 9 ], "interests" : {   
"game" : "game9", "ball" : "ball9", "other" : "nothing9" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb9b"), "userId" : "100101710", "userName" : "Bill Tu10", "gender" : "m10", "age" : 10, "rank" : [ 10, 10, 10 ], "interests" :   
{ "game" : "game10", "ball" : "ball10", "other" : "nothing10" } }  
> db.data_test.find({$nor:[{"age":{$gt:3}},{"rank":{$all:[1,1]}}]})//查詢not (age>3 or rank=all(1,1))  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb93"), "userId" : "10010172", "userName" : "Bill Tu2", "gender" : "m2", "age" : 2, "rank" : [ 2, 2, 2 ], "interests" : {   
"game" : "game2", "ball" : "ball2", "other" : "nothing2" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb94"), "userId" : "10010173", "userName" : "Bill Tu3", "gender" : "m3", "age" : 3, "rank" : [ 3, 3, 3 ], "interests" : {   
"game" : "game3", "ball" : "ball3", "other" : "nothing3" } }  
> db.data_test.find({"rank":{$size:3}})//查詢r(jià)ank數(shù)組大小為3的記錄  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb92"), "userId" : "10010171", "userName" : "Bill Tu1", "gender" : "m1", "age" : 1, "rank" : [ 1, 1, 1 ], "interests" : {   
"game" : "game1", "ball" : "ball1", "other" : "nothing1" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb93"), "userId" : "10010172", "userName" : "Bill Tu2", "gender" : "m2", "age" : 2, "rank" : [ 2, 2, 2 ], "interests" : {   
"game" : "game2", "ball" : "ball2", "other" : "nothing2" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb94"), "userId" : "10010173", "userName" : "Bill Tu3", "gender" : "m3", "age" : 3, "rank" : [ 3, 3, 3 ], "interests" : {   
"game" : "game3", "ball" : "ball3", "other" : "nothing3" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb95"), "userId" : "10010174", "userName" : "Bill Tu4", "gender" : "m4", "age" : 4, "rank" : [ 4, 4, 4 ], "interests" : {   
"game" : "game4", "ball" : "ball4", "other" : "nothing4" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb96"), "userId" : "10010175", "userName" : "Bill Tu5", "gender" : "m5", "age" : 5, "rank" : [ 5, 5, 5 ], "interests" : {   
"game" : "game5", "ball" : "ball5", "other" : "nothing5" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb97"), "userId" : "10010176", "userName" : "Bill Tu6", "gender" : "m6", "age" : 6, "rank" : [ 6, 6, 6 ], "interests" : {   
"game" : "game6", "ball" : "ball6", "other" : "nothing6" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb98"), "userId" : "10010177", "userName" : "Bill Tu7", "gender" : "m7", "age" : 7, "rank" : [ 7, 7, 7 ], "interests" : {   
"game" : "game7", "ball" : "ball7", "other" : "nothing7" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb99"), "userId" : "10010178", "userName" : "Bill Tu8", "gender" : "m8", "age" : 8, "rank" : [ 8, 8, 8 ], "interests" : {   
"game" : "game8", "ball" : "ball8", "other" : "nothing8" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb9a"), "userId" : "10010179", "userName" : "Bill Tu9", "gender" : "m9", "age" : 9, "rank" : [ 9, 9, 9 ], "interests" : {   
"game" : "game9", "ball" : "ball9", "other" : "nothing9" } }  
{ "_id" : ObjectId("4dd7d214b2d55d5e1db1bb9b"), "userId" : "100101710", "userName" : "Bill Tu10", "gender" : "m10", "age" : 10, "rank" : [ 10, 10, 10 ], "interests" :   
{ "game" : "game10", "ball" : "ball10", "other" : "nothing10" } } 


本文出自:億恩科技【www.allwellnessguide.com】

服務(wù)器租用/服務(wù)器托管中國(guó)五強(qiáng)!虛擬主機(jī)域名注冊(cè)頂級(jí)提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]

  • 您可能在找
  • 億恩北京公司:
  • 經(jīng)營(yíng)性ICP/ISP證:京B2-20150015
  • 億恩鄭州公司:
  • 經(jīng)營(yíng)性ICP/ISP/IDC證:豫B1.B2-20060070
  • 億恩南昌公司:
  • 經(jīng)營(yíng)性ICP/ISP證:贛B2-20080012
  • 服務(wù)器/云主機(jī) 24小時(shí)售后服務(wù)電話:0371-60135900
  • 虛擬主機(jī)/智能建站 24小時(shí)售后服務(wù)電話:0371-60135900
  • 專注服務(wù)器托管17年
    掃掃關(guān)注-微信公眾號(hào)
    0371-60135900
    Copyright© 1999-2019 ENKJ All Rights Reserved 億恩科技 版權(quán)所有  地址:鄭州市高新區(qū)翠竹街1號(hào)總部企業(yè)基地億恩大廈  法律顧問(wèn):河南亞太人律師事務(wù)所郝建鋒、杜慧月律師   京公網(wǎng)安備41019702002023號(hào)
      0
     
     
     
     

    0371-60135900
    7*24小時(shí)客服服務(wù)熱線