user2761286 user2761286 - 1 year ago 143
Bash Question

mongoimport imports csv file disordered

I have a 23k rows csv file. When i use mongoimport from shell or import from mongochef somehow it imports with wrong order.

for example i have


csv file. when i import it from shell or mongochef and then .find() it result is ;


any help would be great. Here is my shell command for import ;

mongoimport -d local -c test --type csv --file "C:\Program Files\MongoDB\Example Datasets\abc.csv" --headerline --ignoreBlanks

Answer Source

You could try using --maintainInsertionOrder option.

As the docs say:

If specified, mongoimport inserts the documents in the order of their appearance in the input source, otherwise mongoimport may perform the insertions in an arbitrary order

Also notice that the find default ordering is the natural order that doesn't guarantee returning results by the insertion order. So what I usually do is sorting by the _id field.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download