MongoDB CSV file Import and Export

Source: Internet
Author: User

1. Export to CSV file:

  

2. Import from CSV:

  

data is exported through CSV export, there is a very hidden problem , you need to note when writing code:

Pilot into one data:

    

Where Price is a double type:

    

Then I export the record to demo.csv and delete the record from the database, and then import the record from Demo.csv:

    

Then look at this record in the database:

    

found that the price value of the original double type 66.000000 automatically became the Int32 type 66.

  When the problem arises , you will not get a value if you still use Bson_iter_double (&iter) to fetch the Price field:

    

The value can only be taken with Bson_iter_int32 (&iter):

    

  so get the conclusion :

When you need to fetch a field of type float (or double) in your data, the code should be written as follows:

    

Avoid issues where the field values are not taken after the data has been exported to CSV and then imported from CSV.

MongoDB CSV file Import and Export

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.