MongoDB cursor Snapshot

Source: Internet
Author: User

Sample code

1. Initial data

> Db.snapshot_test.Find(){ "_id": ObjectId ("560ba37c694895b2de42254d"),"name":"Lxy" }{ "_id": ObjectId ("560ba381694895b2de42254e"),"name":"Zyh" }{ "_id": ObjectId ("560ba38a694895b2de422550"),"name":"ZJJ" }{ "_id": ObjectId ("560feb75f31b120ca7308011"),"name":"Yhl"}

2. Add an age field to the NAME=ZJJ line to increase the space occupied by the row

> db.snapshot_test.update ({name:"zjj"},{$set: {name:"zjj ", Age:Ten}})

3. Return to query

> Db.snapshot_test.Find(){ "_id": ObjectId ("560ba37c694895b2de42254d"),"name":"Lxy" }{ "_id": ObjectId ("560ba381694895b2de42254e"),"name":"Zyh" }{ "_id": ObjectId ("560feb75f31b120ca7308011"),"name":"Yhl" }{ "_id": ObjectId ("560ba38a694895b2de422550"),"name":"ZJJ"," Age":Ten}

Because the third row occupies more space, MONGDB will re-allocate the memory space to the third record and add it to the end of the collection

4. Snapshot Query Results

> Db.snapshot_test.Find(). Snapshot () {"_id": ObjectId ("560ba37c694895b2de42254d"),"name":"Lxy" }{ "_id": ObjectId ("560ba381694895b2de42254e"),"name":"Zyh" }{ "_id": ObjectId ("560ba38a694895b2de422550"),"name":"ZJJ"," Age":Ten }{ "_id": ObjectId ("560feb75f31b120ca7308011"),"name":"Yhl"}

As you can see from the returned results, the order of the third row is changed back and the position before the space size is modified

MongoDB cursor Snapshot

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.