mongodb java高级查询实例

来源:互联网 发布:淘宝那里设置破损补寄 编辑:程序博客网 时间:2024/06/05 17:04

转载自:http://blog.csdn.net/tujiyue/article/details/6437821
[java] view plaincopyprint?
  1. /** 
  2.  * MongoDBTest 
  3.  * MongoDB JAVA API的高级查询示例 
  4.  */  
  5. package com.labci.mongodb.test;  
  6. import java.net.UnknownHostException;  
  7. import java.util.Iterator;  
  8. import com.mongodb.BasicDBObject;  
  9. import com.mongodb.DB;  
  10. import com.mongodb.DBCollection;  
  11. import com.mongodb.DBCursor;  
  12. import com.mongodb.DBObject;  
  13. import com.mongodb.Mongo;  
  14. import com.mongodb.MongoException;  
  15. /** 
  16.  * @author Bill Tu(tujiyue/iwtxokhtd) 
  17.  * May 21, 2011[11:33:34 PM] 
  18.  * 
  19.  */  
  20. public class MongoDBAdvancedQuery {  
  21.     private static final String HOST = "192.168.1.86";  
  22.     private static final int PORT = 27017;  
  23.     private static final String USER = "iwtxokhtd";  
  24.     private static final String PASSWORD = "123456";  
  25.     private static final String DB_NAME = "test";  
  26.     private static final String COLLECTION = "data_test";  
  27.     private static Mongo conn=null;  
  28.     private static DB myDB=null;  
  29.     private static DBCollection myCollection=null;  
  30.       
  31.     static{  
  32.         try {  
  33.             conn=new Mongo(HOST,PORT);//建立数据库连接  
  34.             myDB=conn.getDB(DB_NAME);//使用test数据库  
  35.             boolean loginSuccess=myDB.authenticate(USER, PASSWORD.toCharArray());//用户验证  
  36.             if(loginSuccess){  
  37.                 myCollection=myDB.getCollection(COLLECTION);  
  38.             }  
  39.         } catch (UnknownHostException e) {  
  40.             e.printStackTrace();  
  41.         } catch (MongoException e) {  
  42.             e.printStackTrace();  
  43.         }  
  44.     }  
  45.       
  46.     /** 
  47.      * 查询数据 
  48.      * @param collection “表”名 
  49.      */  
  50.     private static void queryData(DBCollection collection){  
  51.         //count查询  
  52.         System.out.println("表的总记录数为:");  
  53.         System.out.println(collection.find().count());  
  54.         //分页查询  
  55.         DBCursor findAll=collection.find();  
  56.         DBCursor queryByPage=findAll.skip(3).limit(4);  
  57.         printData("从第3条记录起取4条记录为:",queryByPage);  
  58.         //order by操作  
  59.         DBObject orderBy = new BasicDBObject();  
  60.         orderBy.put("userName", -1);//按userName倒序排  
  61.         DBCursor orderByResult=collection.find().sort(orderBy);  
  62.         printData("所有记录按userName倒序排为:",orderByResult);  
  63.           
  64.         // "!=" 和 ">" 操作  
  65.         DBObject notEqual=new BasicDBObject();  
  66.         notEqual.put("$ne""Bill Tu10");  
  67.           
  68.         DBObject greatThan=new BasicDBObject();  
  69.         greatThan.put("$gt"7);  
  70.           
  71.         DBObject notEqualAndGreatThan=new BasicDBObject();  
  72.         notEqualAndGreatThan.put("userName", notEqual);  
  73.         notEqualAndGreatThan.put("age", greatThan);  
  74.           
  75.         DBCursor notEqualAndGreatThanResult=collection.find(notEqualAndGreatThan);  
  76.         printData("userName!='Bill Tu10' and age>7的记录为:",notEqualAndGreatThanResult);  
  77.           
  78.         // ">=" 和"<="操作  
  79.         DBObject greatThanEqualAndLessThanEqual=new BasicDBObject();  
  80.         greatThanEqualAndLessThanEqual.put("$gte"2);  
  81.         greatThanEqualAndLessThanEqual.put("$lte"7);  
  82.           
  83.         DBObject ageCompare=new BasicDBObject();  
  84.         ageCompare.put("age",greatThanEqualAndLessThanEqual);  
  85.           
  86.         DBCursor compareResult=collection.find(ageCompare);  
  87.         printData("age>=2 and age<=7的记录为:",compareResult);  
  88.           
  89.         // all操作  
  90.         DBObject all=new BasicDBObject();  
  91.         all.put("$all"new Object[]{7,7});  
  92.           
  93.         DBObject rankAll=new BasicDBObject();  
  94.         rankAll.put("rank", all);  
  95.           
  96.         DBCursor rankAllResult=collection.find(rankAll);  
  97.         printData("rank in all(7,7)的记录为:",rankAllResult);  
  98.           
  99.         //not in操作  
  100.         DBObject notIn=new BasicDBObject();  
  101.         notIn.put("$nin"new Object[]{2,3});  
  102.           
  103.         DBObject ageNotIn=new BasicDBObject();  
  104.         ageNotIn.put("age", notIn);  
  105.           
  106.         DBCursor ageNotInResult=collection.find(ageNotIn);  
  107.         printData("age not in (2,3)的记录为:",ageNotInResult);  
  108.           
  109.         //or操作  
  110.         DBObject orGreatThan=new BasicDBObject("$gt",3);  
  111.         DBObject orRankAll=new BasicDBObject("$all",new Object[]{1,1});  
  112.         DBObject ageOrGreatThan=new BasicDBObject();  
  113.         ageOrGreatThan.put("age", orGreatThan);  
  114.         DBObject rankOrAll=new BasicDBObject();  
  115.         rankOrAll.put("rank", orRankAll);  
  116.           
  117.         DBObject orOperation=new BasicDBObject();  
  118.         orOperation.put("$or"new Object[]{ageOrGreatThan,rankOrAll});  
  119.           
  120.         DBCursor orResult=collection.find(orOperation);  
  121.         printData("age>3 or rank in all(1,1)的记录为:",orResult);  
  122.           
  123.         //not or操作  
  124.         DBObject notOrOperation=new BasicDBObject();  
  125.         notOrOperation.put("$nor"new Object[]{ageOrGreatThan,rankOrAll});  
  126.           
  127.         DBCursor notOrResult=collection.find(notOrOperation);  
  128.         printData("not(age>3 or rank in all(1,1))的记录为:",notOrResult);  
  129.           
  130.         //size 操作  
  131.         DBObject size=new BasicDBObject("$size",3);  
  132.         DBObject rankSize=new BasicDBObject();  
  133.         rankSize.put("rank", size);  
  134.           
  135.         DBCursor sizeResult=collection.find(rankSize);  
  136.         printData("rank数组大小为3的记录为:",sizeResult);  
  137.           
  138.         //exists操作  
  139.         DBObject exists=new BasicDBObject("$exists",false);  
  140.         DBObject userNameExists=new BasicDBObject();  
  141.         userNameExists.put("userName", exists);  
  142.           
  143.         DBCursor userNameExistsResult=collection.find(userNameExists);  
  144.         printData("userName exists false的记录为:",userNameExistsResult);  
  145.           
  146.         //mod 取模操作  
  147.         DBObject modArray=new BasicDBObject("$mod",new Object[]{2,0});  
  148.         DBObject ageMod=new BasicDBObject();  
  149.         ageMod.put("age", modArray);  
  150.           
  151.         DBCursor ageModResult=collection.find(ageMod);  
  152.         printData("age%2==0的记录为:",ageModResult);  
  153.           
  154.     }  
  155.       
  156.     /** 
  157.      * 打印结果数据 
  158.      * @param description 结果数据相关描述 
  159.      * @param recordResult 结果集 
  160.      */  
  161.     private static void printData(String description,DBCursor recordResult){  
  162.         System.out.println(description);  
  163.         for(Iterator<DBObject> iter=recordResult.iterator();iter.hasNext();){  
  164.             System.out.println(iter.next());  
  165.         }  
  166.     }  
  167.       
  168.     /** 
  169.      * @param args 
  170.      */  
  171.     public static void main(String[] args) {  
  172.         queryData(myCollection);  
  173.     }  
  174. }  
 

对应的查询结果:

[java] view plaincopyprint?
  1. 表的总记录数为:  
  2. 10  
  3. 从第3条记录起取4条记录为:  
  4. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f6"} , "userId" : "10010174" , "userName" : "Bill Tu4" , "gender" : "m4" , "age" : 4 , "rank" : [ 4 , 4 , 4] , "interests" : { "game" : "game4" , "ball" : "ball4" , "other" : "nothing4"}}  
  5. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f7"} , "userId" : "10010175" , "userName" : "Bill Tu5" , "gender" : "m5" , "age" : 5 , "rank" : [ 5 , 5 , 5] , "interests" : { "game" : "game5" , "ball" : "ball5" , "other" : "nothing5"}}  
  6. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f8"} , "userId" : "10010176" , "userName" : "Bill Tu6" , "gender" : "m6" , "age" : 6 , "rank" : [ 6 , 6 , 6] , "interests" : { "game" : "game6" , "ball" : "ball6" , "other" : "nothing6"}}  
  7. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f9"} , "userId" : "10010177" , "userName" : "Bill Tu7" , "gender" : "m7" , "age" : 7 , "rank" : [ 7 , 7 , 7] , "interests" : { "game" : "game7" , "ball" : "ball7" , "other" : "nothing7"}}  
  8. 所有记录按userName倒序排为:  
  9. "_id" : { "$oid" : "4dd8a274b2d556790b0b37fb"} , "userId" : "10010179" , "userName" : "Bill Tu9" , "gender" : "m9" , "age" : 9 , "rank" : [ 9 , 9 , 9] , "interests" : { "game" : "game9" , "ball" : "ball9" , "other" : "nothing9"}}  
  10. "_id" : { "$oid" : "4dd8a274b2d556790b0b37fa"} , "userId" : "10010178" , "userName" : "Bill Tu8" , "gender" : "m8" , "age" : 8 , "rank" : [ 8 , 8 , 8] , "interests" : { "game" : "game8" , "ball" : "ball8" , "other" : "nothing8"}}  
  11. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f9"} , "userId" : "10010177" , "userName" : "Bill Tu7" , "gender" : "m7" , "age" : 7 , "rank" : [ 7 , 7 , 7] , "interests" : { "game" : "game7" , "ball" : "ball7" , "other" : "nothing7"}}  
  12. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f8"} , "userId" : "10010176" , "userName" : "Bill Tu6" , "gender" : "m6" , "age" : 6 , "rank" : [ 6 , 6 , 6] , "interests" : { "game" : "game6" , "ball" : "ball6" , "other" : "nothing6"}}  
  13. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f7"} , "userId" : "10010175" , "userName" : "Bill Tu5" , "gender" : "m5" , "age" : 5 , "rank" : [ 5 , 5 , 5] , "interests" : { "game" : "game5" , "ball" : "ball5" , "other" : "nothing5"}}  
  14. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f6"} , "userId" : "10010174" , "userName" : "Bill Tu4" , "gender" : "m4" , "age" : 4 , "rank" : [ 4 , 4 , 4] , "interests" : { "game" : "game4" , "ball" : "ball4" , "other" : "nothing4"}}  
  15. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f5"} , "userId" : "10010173" , "userName" : "Bill Tu3" , "gender" : "m3" , "age" : 3 , "rank" : [ 3 , 3 , 3] , "interests" : { "game" : "game3" , "ball" : "ball3" , "other" : "nothing3"}}  
  16. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f4"} , "userId" : "10010172" , "userName" : "Bill Tu2" , "gender" : "m2" , "age" : 2 , "rank" : [ 2 , 2 , 2] , "interests" : { "game" : "game2" , "ball" : "ball2" , "other" : "nothing2"}}  
  17. "_id" : { "$oid" : "4dd8a274b2d556790b0b37fc"} , "userId" : "100101710" , "userName" : "Bill Tu10" , "gender" : "m10" , "age" : 10 , "rank" : [ 10 , 10 , 10] , "interests" : { "game" : "game10" , "ball" : "ball10" , "other" : "nothing10"}}  
  18. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f3"} , "userId" : "10010171" , "userName" : "Bill Tu1" , "gender" : "m1" , "age" : 1 , "rank" : [ 1 , 1 , 1] , "interests" : { "game" : "game1" , "ball" : "ball1" , "other" : "nothing1"}}  
  19. userName!='Bill Tu10' and age>7的记录为:  
  20. "_id" : { "$oid" : "4dd8a274b2d556790b0b37fa"} , "userId" : "10010178" , "userName" : "Bill Tu8" , "gender" : "m8" , "age" : 8 , "rank" : [ 8 , 8 , 8] , "interests" : { "game" : "game8" , "ball" : "ball8" , "other" : "nothing8"}}  
  21. "_id" : { "$oid" : "4dd8a274b2d556790b0b37fb"} , "userId" : "10010179" , "userName" : "Bill Tu9" , "gender" : "m9" , "age" : 9 , "rank" : [ 9 , 9 , 9] , "interests" : { "game" : "game9" , "ball" : "ball9" , "other" : "nothing9"}}  
  22. age>=2 and age<=7的记录为:  
  23. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f4"} , "userId" : "10010172" , "userName" : "Bill Tu2" , "gender" : "m2" , "age" : 2 , "rank" : [ 2 , 2 , 2] , "interests" : { "game" : "game2" , "ball" : "ball2" , "other" : "nothing2"}}  
  24. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f5"} , "userId" : "10010173" , "userName" : "Bill Tu3" , "gender" : "m3" , "age" : 3 , "rank" : [ 3 , 3 , 3] , "interests" : { "game" : "game3" , "ball" : "ball3" , "other" : "nothing3"}}  
  25. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f6"} , "userId" : "10010174" , "userName" : "Bill Tu4" , "gender" : "m4" , "age" : 4 , "rank" : [ 4 , 4 , 4] , "interests" : { "game" : "game4" , "ball" : "ball4" , "other" : "nothing4"}}  
  26. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f7"} , "userId" : "10010175" , "userName" : "Bill Tu5" , "gender" : "m5" , "age" : 5 , "rank" : [ 5 , 5 , 5] , "interests" : { "game" : "game5" , "ball" : "ball5" , "other" : "nothing5"}}  
  27. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f8"} , "userId" : "10010176" , "userName" : "Bill Tu6" , "gender" : "m6" , "age" : 6 , "rank" : [ 6 , 6 , 6] , "interests" : { "game" : "game6" , "ball" : "ball6" , "other" : "nothing6"}}  
  28. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f9"} , "userId" : "10010177" , "userName" : "Bill Tu7" , "gender" : "m7" , "age" : 7 , "rank" : [ 7 , 7 , 7] , "interests" : { "game" : "game7" , "ball" : "ball7" , "other" : "nothing7"}}  
  29. rank in all(7,7)的记录为:  
  30. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f9"} , "userId" : "10010177" , "userName" : "Bill Tu7" , "gender" : "m7" , "age" : 7 , "rank" : [ 7 , 7 , 7] , "interests" : { "game" : "game7" , "ball" : "ball7" , "other" : "nothing7"}}  
  31. age not in (2,3)的记录为:  
  32. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f3"} , "userId" : "10010171" , "userName" : "Bill Tu1" , "gender" : "m1" , "age" : 1 , "rank" : [ 1 , 1 , 1] , "interests" : { "game" : "game1" , "ball" : "ball1" , "other" : "nothing1"}}  
  33. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f6"} , "userId" : "10010174" , "userName" : "Bill Tu4" , "gender" : "m4" , "age" : 4 , "rank" : [ 4 , 4 , 4] , "interests" : { "game" : "game4" , "ball" : "ball4" , "other" : "nothing4"}}  
  34. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f7"} , "userId" : "10010175" , "userName" : "Bill Tu5" , "gender" : "m5" , "age" : 5 , "rank" : [ 5 , 5 , 5] , "interests" : { "game" : "game5" , "ball" : "ball5" , "other" : "nothing5"}}  
  35. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f8"} , "userId" : "10010176" , "userName" : "Bill Tu6" , "gender" : "m6" , "age" : 6 , "rank" : [ 6 , 6 , 6] , "interests" : { "game" : "game6" , "ball" : "ball6" , "other" : "nothing6"}}  
  36. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f9"} , "userId" : "10010177" , "userName" : "Bill Tu7" , "gender" : "m7" , "age" : 7 , "rank" : [ 7 , 7 , 7] , "interests" : { "game" : "game7" , "ball" : "ball7" , "other" : "nothing7"}}  
  37. "_id" : { "$oid" : "4dd8a274b2d556790b0b37fa"} , "userId" : "10010178" , "userName" : "Bill Tu8" , "gender" : "m8" , "age" : 8 , "rank" : [ 8 , 8 , 8] , "interests" : { "game" : "game8" , "ball" : "ball8" , "other" : "nothing8"}}  
  38. "_id" : { "$oid" : "4dd8a274b2d556790b0b37fb"} , "userId" : "10010179" , "userName" : "Bill Tu9" , "gender" : "m9" , "age" : 9 , "rank" : [ 9 , 9 , 9] , "interests" : { "game" : "game9" , "ball" : "ball9" , "other" : "nothing9"}}  
  39. "_id" : { "$oid" : "4dd8a274b2d556790b0b37fc"} , "userId" : "100101710" , "userName" : "Bill Tu10" , "gender" : "m10" , "age" : 10 , "rank" : [ 10 , 10 , 10] , "interests" : { "game" : "game10" , "ball" : "ball10" , "other" : "nothing10"}}  
  40. age>3 or rank in all(1,1)的记录为:  
  41. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f3"} , "userId" : "10010171" , "userName" : "Bill Tu1" , "gender" : "m1" , "age" : 1 , "rank" : [ 1 , 1 , 1] , "interests" : { "game" : "game1" , "ball" : "ball1" , "other" : "nothing1"}}  
  42. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f6"} , "userId" : "10010174" , "userName" : "Bill Tu4" , "gender" : "m4" , "age" : 4 , "rank" : [ 4 , 4 , 4] , "interests" : { "game" : "game4" , "ball" : "ball4" , "other" : "nothing4"}}  
  43. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f7"} , "userId" : "10010175" , "userName" : "Bill Tu5" , "gender" : "m5" , "age" : 5 , "rank" : [ 5 , 5 , 5] , "interests" : { "game" : "game5" , "ball" : "ball5" , "other" : "nothing5"}}  
  44. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f8"} , "userId" : "10010176" , "userName" : "Bill Tu6" , "gender" : "m6" , "age" : 6 , "rank" : [ 6 , 6 , 6] , "interests" : { "game" : "game6" , "ball" : "ball6" , "other" : "nothing6"}}  
  45. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f9"} , "userId" : "10010177" , "userName" : "Bill Tu7" , "gender" : "m7" , "age" : 7 , "rank" : [ 7 , 7 , 7] , "interests" : { "game" : "game7" , "ball" : "ball7" , "other" : "nothing7"}}  
  46. "_id" : { "$oid" : "4dd8a274b2d556790b0b37fa"} , "userId" : "10010178" , "userName" : "Bill Tu8" , "gender" : "m8" , "age" : 8 , "rank" : [ 8 , 8 , 8] , "interests" : { "game" : "game8" , "ball" : "ball8" , "other" : "nothing8"}}  
  47. "_id" : { "$oid" : "4dd8a274b2d556790b0b37fb"} , "userId" : "10010179" , "userName" : "Bill Tu9" , "gender" : "m9" , "age" : 9 , "rank" : [ 9 , 9 , 9] , "interests" : { "game" : "game9" , "ball" : "ball9" , "other" : "nothing9"}}  
  48. "_id" : { "$oid" : "4dd8a274b2d556790b0b37fc"} , "userId" : "100101710" , "userName" : "Bill Tu10" , "gender" : "m10" , "age" : 10 , "rank" : [ 10 , 10 , 10] , "interests" : { "game" : "game10" , "ball" : "ball10" , "other" : "nothing10"}}  
  49. not(age>3 or rank in all(1,1))的记录为:  
  50. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f4"} , "userId" : "10010172" , "userName" : "Bill Tu2" , "gender" : "m2" , "age" : 2 , "rank" : [ 2 , 2 , 2] , "interests" : { "game" : "game2" , "ball" : "ball2" , "other" : "nothing2"}}  
  51. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f5"} , "userId" : "10010173" , "userName" : "Bill Tu3" , "gender" : "m3" , "age" : 3 , "rank" : [ 3 , 3 , 3] , "interests" : { "game" : "game3" , "ball" : "ball3" , "other" : "nothing3"}}  
  52. rank数组大小为3的记录为:  
  53. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f3"} , "userId" : "10010171" , "userName" : "Bill Tu1" , "gender" : "m1" , "age" : 1 , "rank" : [ 1 , 1 , 1] , "interests" : { "game" : "game1" , "ball" : "ball1" , "other" : "nothing1"}}  
  54. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f4"} , "userId" : "10010172" , "userName" : "Bill Tu2" , "gender" : "m2" , "age" : 2 , "rank" : [ 2 , 2 , 2] , "interests" : { "game" : "game2" , "ball" : "ball2" , "other" : "nothing2"}}  
  55. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f5"} , "userId" : "10010173" , "userName" : "Bill Tu3" , "gender" : "m3" , "age" : 3 , "rank" : [ 3 , 3 , 3] , "interests" : { "game" : "game3" , "ball" : "ball3" , "other" : "nothing3"}}  
  56. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f6"} , "userId" : "10010174" , "userName" : "Bill Tu4" , "gender" : "m4" , "age" : 4 , "rank" : [ 4 , 4 , 4] , "interests" : { "game" : "game4" , "ball" : "ball4" , "other" : "nothing4"}}  
  57. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f7"} , "userId" : "10010175" , "userName" : "Bill Tu5" , "gender" : "m5" , "age" : 5 , "rank" : [ 5 , 5 , 5] , "interests" : { "game" : "game5" , "ball" : "ball5" , "other" : "nothing5"}}  
  58. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f8"} , "userId" : "10010176" , "userName" : "Bill Tu6" , "gender" : "m6" , "age" : 6 , "rank" : [ 6 , 6 , 6] , "interests" : { "game" : "game6" , "ball" : "ball6" , "other" : "nothing6"}}  
  59. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f9"} , "userId" : "10010177" , "userName" : "Bill Tu7" , "gender" : "m7" , "age" : 7 , "rank" : [ 7 , 7 , 7] , "interests" : { "game" : "game7" , "ball" : "ball7" , "other" : "nothing7"}}  
  60. "_id" : { "$oid" : "4dd8a274b2d556790b0b37fa"} , "userId" : "10010178" , "userName" : "Bill Tu8" , "gender" : "m8" , "age" : 8 , "rank" : [ 8 , 8 , 8] , "interests" : { "game" : "game8" , "ball" : "ball8" , "other" : "nothing8"}}  
  61. "_id" : { "$oid" : "4dd8a274b2d556790b0b37fb"} , "userId" : "10010179" , "userName" : "Bill Tu9" , "gender" : "m9" , "age" : 9 , "rank" : [ 9 , 9 , 9] , "interests" : { "game" : "game9" , "ball" : "ball9" , "other" : "nothing9"}}  
  62. "_id" : { "$oid" : "4dd8a274b2d556790b0b37fc"} , "userId" : "100101710" , "userName" : "Bill Tu10" , "gender" : "m10" , "age" : 10 , "rank" : [ 10 , 10 , 10] , "interests" : { "game" : "game10" , "ball" : "ball10" , "other" : "nothing10"}}  
  63. userName exists false的记录为:  
  64. age%2==0的记录为:  
  65. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f4"} , "userId" : "10010172" , "userName" : "Bill Tu2" , "gender" : "m2" , "age" : 2 , "rank" : [ 2 , 2 , 2] , "interests" : { "game" : "game2" , "ball" : "ball2" , "other" : "nothing2"}}  
  66. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f6"} , "userId" : "10010174" , "userName" : "Bill Tu4" , "gender" : "m4" , "age" : 4 , "rank" : [ 4 , 4 , 4] , "interests" : { "game" : "game4" , "ball" : "ball4" , "other" : "nothing4"}}  
  67. "_id" : { "$oid" : "4dd8a274b2d556790b0b37f8"} , "userId" : "10010176" , "userName" : "Bill Tu6" , "gender" : "m6" , "age" : 6 , "rank" : [ 6 , 6 , 6] , "interests" : { "game" : "game6" , "ball" : "ball6" , "other" : "nothing6"}}  
  68. "_id" : { "$oid" : "4dd8a274b2d556790b0b37fa"} , "userId" : "10010178" , "userName" : "Bill Tu8" , "gender" : "m8" , "age" : 8 , "rank" : [ 8 , 8 , 8] , "interests" : { "game" : "game8" , "ball" : "ball8" , "other" : "nothing8"}}  
  69. "_id" : { "$oid" : "4dd8a274b2d556790b0b37fc"} , "userId" : "100101710" , "userName" : "Bill Tu10" , "gender" : "m10" , 

0 0
原创粉丝点击