MongoDB Operations Manual CRUD query pointers

Source: Internet
Author: User

Enumerate traversal pointers Overviewas already mentioned, Db.collection.find () If you do not assign a variable to a VAR declaration, the first 20 records are automatically enumerated.
manually Enumerate pointersIn the MONGO console, assign the query to a VAR-declared variable so that it is not automatically enumerated.
var cur = db.testData.find ();
Then each time this pointer is called, 20 is automatically traversed
cur;
You can also use the next () method of the pointer to get the next record
var cur = db.testData.find ();
while (Cur.hasnext ())
{
Print (Tojson (Cur.next ()));Here the print operation can be replaced with Printjson:Printjson (Cur.next ());
}
You can use the foreach () method of the pointer to traverse the pointer data:
var cur = db.testData.find ();
Cur.foreach (Printjson);
Enumerate subscriptin the MONGO console, you can use the ToArray () method to access the pointer results.
var cur=db.testdata.find ();
var arr = Cur.toarray ();
var item = arr[2];
The ToArray () method loads all the query results into memory, and this method iterates through the pointer.
In addition, some drivers provide a way to directly use the array subscript, which is called the abbreviation for ToArray ().
var cur=db.testdata.find ();
var item = cur[3];
The above two sentences are equivalent to cur.toarray () [3];

MongoDB Operations Manual CRUD query pointers

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.