The data returned by Python using Db.select can only be traversed once

Source: Internet
Author: User

The data found in Python through find from MONGO, or the data returned through select, actually returns a cursor, and when you make a convenient one, the cursor points to the last,

So when you do the convenience again, there is a phenomenon of empty data.

WORKAROUND: Convert data through list () lists = list (data returned in MONGO)

But then there are new problems:

1.list converted data only refers to, not specified

2. When the data is too large, the performance of the fried chicken is bad when the data is converted.

Workaround:

1. Use namedtuple and Map object.

2. When using map and namedtuple, cursors use the Fetchall () method. Fetch all the results one line at a time, and then call the map method to map all the data to the Record object.

3. The returned map object can be traversed by calling the For method. The map object resembles a Record object list.

4.namedtuple generated objects, accessed by the dot to access the data.

    

The data returned by Python using Db.select can only be traversed once

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.