The document structure is as follows:
{"_id": ObjectId ("55dc145ef754a3342000002d"), "id": "title": "Hot summer, with me high!" "Content": "The heat of the July, can hardly endure ~~~! Summer. It should be a paradise surrounded by watermelons, chilled cola, family barrels, air conditioning and games. Outside of the world is a chaos and I have nothing to do ~ wow haha ha!! "," thumb ":"/201506/5592560017b6a.jpg "," banner ":"/201506/559255fa5366d.jpg "," order ": One," Publish_time " : "2015-08-25", "game_num": +, "Games": [{"id": 1128, "Name_zh": "Chasing the Beast", "Apk_size": "38.15M", "Apk_version_name": "1.0.6", "Apk_package_name": "Com.miniclip.beastq Uest "," Apk_version_code ":" + "," Game_rank ": 8," Customize_update_time ":" 2015-05-18 00:00:00 ",}, {" id ": 3276," Name_zh ":" World Zombie Big league "," Apk_size ":" 33.88M ", "Apk_version_name": "3.3.3237", "Apk_package_name": "Com.proletariat.worldzombination", "Apk_version_code": "33537", "Game_rank": 8, "Customize_updatE_time ":" 2015-05-15 00:00:00 ",}, {" id ": 3416," Name_zh ":" Siege Alien "," a Pk_size ":" 38.69M "," Apk_version_name ":" 1.7.1 "," Apk_package_name ":" com.outplayentertainment.al Iencreeps "," Apk_version_code ":" 10070010 "," Game_rank ": 8," Customize_update_time ":" 2015-04-25 00:00:00 ",}, {" id ": 10357," Name_zh ":" Alloy Warhead: Defense "," Apk_size " : "47.13M", "Apk_version_name": "1.27.0", "Apk_package_name": "com.snkplaymore.android003", "Apk_version_code": "Game_rank": 8, "Customize_update_time": "0000-00-00 00:00:00", }, {"id": 10360, "Name_zh": "Green Ninja Frog Year", "Apk_size": "47.7M", " Apk_version_name ":" 4 "," Apk_package_name ":" Com.nitrome.greenninja "," Apk_version_code ":" 4 ", "Game_rank": 8, "Customize_update_time": "2015-06-30 15:52:10",}, {"id": 10364, "Nam E_zh ":" Kill Mario "," apk_size ":" 31.16M "," Apk_version_name ":" 1.0.6 "," Apk_package_name " : "Air.com.keybol.plumber", "Apk_version_code": "1000006", "Game_rank": 7, "Customize_u Pdate_time ":" 2015-06-30 16:08:09 ",}, {" id ": 10366," Name_zh ":" Conquer the World by breeding ", "Apk_size": "44.83M", "Apk_version_name": "1.0.2", "Apk_package_name": "Com.kt.SpermWarWor Ldwide_g "," Apk_version_code ":" 10002 "," Game_rank ": 8," Customize_update_time ":" 2015 -06-30 16:21:22 ",}, {" id ": 10229," Name_zh ":" Ice Cube Cut "," apk_size ":" 7. " 14M "," Apk_version_name ":" 2.4.6 "," Apk_package_name ":" Com.hyperkani.sliceice "," Apk_v Ersion_code ":" 30 ", "Game_rank": 7, "Customize_update_time": "2014-11-04 00:00:00",}, {"id": 10356, "Name_zh": "The Strange house eating ice cream", "apk_size": "33.56M", "Apk_version_name": "1.0.2", "Apk_package_name": "Com.firedroid.icecreamnomsters", "Apk_version_code": "4", "Game_rank" : 8, "Customize_update_time": "0000-00-00 00:00:00",}, {"id": 10358, " Name_zh ":" Cup of Juice "," apk_size ":" 42.11M "," Apk_version_name ":" 1.6.21 "," Apk_package_nam E ":" AIR.COM.SGN.JUICEJAM.GP "," Apk_version_code ":" 1006021 "," Game_rank ": 6," Customi Ze_update_time ":" 0000-00-00 00:00:00 ",}, {" id ": 10362," Name_zh ":" Mr. Sleepwalking ", "Apk_size": "48.52M", "Apk_version_name": "1.00", "apk_package_name": "com." Bebit.mrsnoozleberg "," Apk_veRsion_code ":" 1 "," Game_rank ": 8," Customize_update_time ":" 2015-06-30 15:58:13 ",}, {"id": 10363, "Name_zh": "Cool square ice Ice", "apk_size": "23.14M", "Apk_version_na Me ":" 1.1 "," Apk_package_name ":" Com.unilever.CoolCubeszzc "," Apk_version_code ":" 2 ", "Game_rank": 6, "Customize_update_time": "2015-06-30 16:04:56",}, {"id": 10365, "Name_zh": "Bloodthirsty shark 2", "Apk_size": "9.9M", "Apk_version_name": "2.6.1", "apk_p Ackage_name ":" Com.fgol.shark2 "," Apk_version_code ":", "" Game_rank ": 8," customize_ Update_time ":" 2015-06-30 16:15:58 ",}, {" id ": 10367," Name_zh ":" Aliens Love Milk ", "Apk_size": "23.86M", "Apk_version_name": "1.0.7", "Apk_package_name": "Air.com.rightfusion. Alienslikemilk ", "Apk_version_code": "1000007", "Game_rank": 8, "Customize_update_time": "2015-06-30 16:28:17" , } ]}
How to page up a paging query for a child document
such as fetching only 3 data at a time
{"id": 1128, "Name_zh": "Chasing the Beast", "Apk_size": "38.15M", "Apk_version_name": "1.0.6", "Apk_package_name": "Com.miniclip.beastquest", "Apk_version_code": "+", "gam E_rank ": 8," Customize_update_time ":" 2015-05-18 00:00:00 ",}, {" id ": 3276, "Name_zh": "World Zombie Big league", "Apk_size": "33.88M", "Apk_version_name": "3.3.3237", "apk _package_name ":" Com.proletariat.worldzombination "," Apk_version_code ":" 33537 "," Game_rank ": 8, "Customize_update_time": "2015-05-15 00:00:00",}, {"id": 3416, "name_z H ":" Encirclement and suppression of extraterrestrial guests "," apk_size ":" 38.69M "," Apk_version_name ":" 1.7.1 "," Apk_package_name ":" Com.outplayentertainment.aliencreeps "," Apk_version_code ":" 10070010 "," Game_rank ": 8, "Customize_update_time": "2015-04-25 00:00:00",}}
Reply content:
The document structure is as follows:
{"_id": ObjectId ("55dc145ef754a3342000002d"), "id": "title": "Hot summer, with me high!" "Content": "The heat of the July, can hardly endure ~~~! Summer. It should be a paradise surrounded by watermelons, chilled cola, family barrels, air conditioning and games. Outside of the world is a chaos and I have nothing to do ~ wow haha ha!! "," thumb ":"/201506/5592560017b6a.jpg "," banner ":"/201506/559255fa5366d.jpg "," order ": One," Publish_time " : "2015-08-25", "game_num": +, "Games": [{"id": 1128, "Name_zh": "Chasing the Beast", "Apk_size": "38.15M", "Apk_version_name": "1.0.6", "Apk_package_name": "Com.miniclip.beastq Uest "," Apk_version_code ":" + "," Game_rank ": 8," Customize_update_time ":" 2015-05-18 00:00:00 ",}, {" id ": 3276," Name_zh ":" World Zombie Big league "," Apk_size ":" 33.88M ", "Apk_version_name": "3.3.3237", "Apk_package_name": "Com.proletariat.worldzombination", "Apk_version_code": "33537", "Game_rank": 8, "Customize_updatE_time ":" 2015-05-15 00:00:00 ",}, {" id ": 3416," Name_zh ":" Siege Alien "," a Pk_size ":" 38.69M "," Apk_version_name ":" 1.7.1 "," Apk_package_name ":" com.outplayentertainment.al Iencreeps "," Apk_version_code ":" 10070010 "," Game_rank ": 8," Customize_update_time ":" 2015-04-25 00:00:00 ",}, {" id ": 10357," Name_zh ":" Alloy Warhead: Defense "," Apk_size " : "47.13M", "Apk_version_name": "1.27.0", "Apk_package_name": "com.snkplaymore.android003", "Apk_version_code": "Game_rank": 8, "Customize_update_time": "0000-00-00 00:00:00", }, {"id": 10360, "Name_zh": "Green Ninja Frog Year", "Apk_size": "47.7M", " Apk_version_name ":" 4 "," Apk_package_name ":" Com.nitrome.greenninja "," Apk_version_code ":" 4 ", "Game_rank": 8, "Customize_update_time": "2015-06-30 15:52:10",}, {"id": 10364, "Nam E_zh ":" Kill Mario "," apk_size ":" 31.16M "," Apk_version_name ":" 1.0.6 "," Apk_package_name " : "Air.com.keybol.plumber", "Apk_version_code": "1000006", "Game_rank": 7, "Customize_u Pdate_time ":" 2015-06-30 16:08:09 ",}, {" id ": 10366," Name_zh ":" Conquer the World by breeding ", "Apk_size": "44.83M", "Apk_version_name": "1.0.2", "Apk_package_name": "Com.kt.SpermWarWor Ldwide_g "," Apk_version_code ":" 10002 "," Game_rank ": 8," Customize_update_time ":" 2015 -06-30 16:21:22 ",}, {" id ": 10229," Name_zh ":" Ice Cube Cut "," apk_size ":" 7. " 14M "," Apk_version_name ":" 2.4.6 "," Apk_package_name ":" Com.hyperkani.sliceice "," Apk_v Ersion_code ":" 30 ", "Game_rank": 7, "Customize_update_time": "2014-11-04 00:00:00",}, {"id": 10356, "Name_zh": "The Strange house eating ice cream", "apk_size": "33.56M", "Apk_version_name": "1.0.2", "Apk_package_name": "Com.firedroid.icecreamnomsters", "Apk_version_code": "4", "Game_rank" : 8, "Customize_update_time": "0000-00-00 00:00:00",}, {"id": 10358, " Name_zh ":" Cup of Juice "," apk_size ":" 42.11M "," Apk_version_name ":" 1.6.21 "," Apk_package_nam E ":" AIR.COM.SGN.JUICEJAM.GP "," Apk_version_code ":" 1006021 "," Game_rank ": 6," Customi Ze_update_time ":" 0000-00-00 00:00:00 ",}, {" id ": 10362," Name_zh ":" Mr. Sleepwalking ", "Apk_size": "48.52M", "Apk_version_name": "1.00", "apk_package_name": "com." Bebit.mrsnoozleberg "," Apk_veRsion_code ":" 1 "," Game_rank ": 8," Customize_update_time ":" 2015-06-30 15:58:13 ",}, {"id": 10363, "Name_zh": "Cool square ice Ice", "apk_size": "23.14M", "Apk_version_na Me ":" 1.1 "," Apk_package_name ":" Com.unilever.CoolCubeszzc "," Apk_version_code ":" 2 ", "Game_rank": 6, "Customize_update_time": "2015-06-30 16:04:56",}, {"id": 10365, "Name_zh": "Bloodthirsty shark 2", "Apk_size": "9.9M", "Apk_version_name": "2.6.1", "apk_p Ackage_name ":" Com.fgol.shark2 "," Apk_version_code ":", "" Game_rank ": 8," customize_ Update_time ":" 2015-06-30 16:15:58 ",}, {" id ": 10367," Name_zh ":" Aliens Love Milk ", "Apk_size": "23.86M", "Apk_version_name": "1.0.7", "Apk_package_name": "Air.com.rightfusion. Alienslikemilk ", "Apk_version_code": "1000007", "Game_rank": 8, "Customize_update_time": "2015-06-30 16:28:17" , } ]}
How to page up a paging query for a child document
such as fetching only 3 data at a time
{"id": 1128, "Name_zh": "Chasing the Beast", "Apk_size": "38.15M", "Apk_version_name": "1.0.6", "Apk_package_name": "Com.miniclip.beastquest", "Apk_version_code": "+", "gam E_rank ": 8," Customize_update_time ":" 2015-05-18 00:00:00 ",}, {" id ": 3276, "Name_zh": "World Zombie Big league", "Apk_size": "33.88M", "Apk_version_name": "3.3.3237", "apk _package_name ":" Com.proletariat.worldzombination "," Apk_version_code ":" 33537 "," Game_rank ": 8, "Customize_update_time": "2015-05-15 00:00:00",}, {"id": 3416, "name_z H ":" Encirclement and suppression of extraterrestrial guests "," apk_size ":" 38.69M "," Apk_version_name ":" 1.7.1 "," Apk_package_name ":" Com.outplayentertainment.aliencreeps "," Apk_version_code ":" 10070010 "," Game_rank ": 8, "Customize_update_time": "2015-04-25 00:00:00",}}
> Db.test1.find (). Pretty () {"_id": ObjectId ("55dc145ef754a3342000002d"), "games": [{"id": 1128, "Name_zh": "Chasing the Beast", "Customize_update_time": "2015-05-18 00:00:00"}, { "id": 3276, "Name_zh": "Dasda", "Customize_update_time": "2015-05-15 00:00:00"}, {"id": 3416, "Name_zh": "Siege Alien", "Customize_update_time": "2015-04-25 00:00:00" }, {"id": 10357, "Name_zh": "Alloy Warhead: Defense", "Customize_update_time": "0000-00- XX 00:00:00 "}, {" id ": 10360," Name_zh ":" Green Ninja Frog Year "," Customize_update_tim E ":" 2015-06-30 15:52:10 "}, {" id ": 10364," Name_zh ":" Kill Mario "," Customi Ze_update_time ":" 2015-06-30 16:08:09 "}, {" id ": 10366," Name_zh ":" Conquer the World by breeding ", "Customize_updatE_time ":" 2015-06-30 16:21:22 "}, {" id ": 10229," Name_zh ":" Ice Cube Cut "," cus Tomize_update_time ":" 2014-11-04 00:00:00 "}, {" id ": 10356," Name_zh ":" The strange house to eat ice cream ", "Customize_update_time": "0000-00-00 00:00:00"}, {"id": 10358, "name_z H ":" Cup of Juice "," customize_update_time ":" 0000-00-00 00:00:00 "}, {" id ": 10362, "Name_zh": "Mr. Sleepwalking", "Customize_update_time": "2015-06-30 15:58:13"}, {"id": 1 0363, "Name_zh": "Cool square ice Ice", "Customize_update_time": "2015-06-30 16:04:56"}, { "id": 10365, "Name_zh": "Bloodthirsty shark 2", "Customize_update_time": "2015-06-30 16:15:58"}, {"id": 10367, "Name_zh": "Alien Love Milk", "customize_update_time": "2015-06-30 16:28:17 " } ]}
Take the first 3 data of games:
> db.test1.find({"_id" : ObjectId("55dc145ef754a3342000002d")},{"games":{ "$slice":[0,3]}}).pretty(){ "_id" : ObjectId("55dc145ef754a3342000002d"), "games" : [ { "id" : 1128, "name_zh" : "追击野兽", "customize_update_time" : "2015-05-18 00:00:00" }, { "id" : 3276, "name_zh" : "dasda", "customize_update_time" : "2015-05-15 00:00:00" }, { "id" : 3416, "name_zh" : "围剿外星客", "customize_update_time" : "2015-04-25 00:00:00" } ]}
Take fourth to 6th data:
> db.test1.find({"_id" : ObjectId("55dc145ef754a3342000002d")},{"games":{ "$slice":[3,3]}}).pretty(){ "_id" : ObjectId("55dc145ef754a3342000002d"), "games" : [ { "id" : 10357, "name_zh" : "合金弹头:防御", "customize_update_time" : "0000-00-00 00:00:00" }, { "id" : 10360, "name_zh" : "绿色忍者蛙年", "customize_update_time" : "2015-06-30 15:52:10" }, { "id" : 10364, "name_zh" : "杀死马里奥", "customize_update_time" : "2015-06-30 16:08:09" } ]}
And so on, then. "$slice": [3,3] The first 3 indicates the starting position of the index of the query array, and the second 3 indicates the number of data bars to be taken. It is recommended that the games not be too much, or it will exceed the document limit of 16M. But this may be a design problem, I think more.
The second method is to take the code out of the database, each subdocument inside the games is encapsulated into model, put in the cache for paging, rather than the database-level paging can also be implemented
The third method: from the data can be seen in the games inside the subdocuments are sorted by ID, then that is, the sub-document is comparable, then you can use $GT and $lt, splicing $size fetch data, I did not try. You can try it. But $slice is a little easier to get a subset of arrays.
Use limit (n) to restrict access to only n data. Skip (n) can skip n data, the combination of the two can achieve paging it? However, skip is better at consuming less resources.