1. Inserting experimental data
Lazy to use the samus,100 bar.
1 for(inti =0; I < -; i++)2 {3Document doc =NewDocument ();4doc["ID"] =i;5doc["MSG"] ="value is"+i;6 Mongocollection.insert (DOC);7}
Insert Successful
2. Paging
Method One: Through the Sike () and the Limit () method, for example,
by Db.myCollection.find (). Sort ({"ID": 1}). Skip (10) command, after sorting it by ID, skip 10, Query 10, and the result is 10-19 data.
This is similar to the operation of the Skip () and take () methods under the EF framework.
Method Two: Obtain the last record of the previous page, after the query of the specified bar record, such as,
Store the previous 10 records in TMP, latest the last record of the previous page (9th), in the next query, through the find parameters, filter to go to the previous record, get the following 10 records.
3. Comparison of two different methods
The method is relatively simple, but the skip method is inefficient, and it is more recommended to use method two in the case of large amounts of data, but it may take up more memory space.
MongoDB Implementation Paging (two methods)