Question

I do

mongoimport --host myhost --port myport --db mydb --collection mycollection --fields field_one,field_two --type csv --file myfile.csv

And this returns without error (even if I add --stopOnError it returns with exist status 0 and no errors).

Then if I do

mongo myhost:myport/mydb --eval "db.mycollection.find()"

and it returns

DBQuery: mydb.mycollection -> undefined

However, when I log into the mongo console I see that the data is there.

mongo myhost:myport/mydb
> db.mycollection.find()
// data here

Any suggestions? I'm using mongo 2.2.

I saw the similar question mongoimport is not showing the collection after import has run successfully, but checking the server logs I'm not seeing anything amiss.

Était-ce utile?

La solution

The ".find()" call returns a cursor. The shell adds value in that it will iterate over the cursor and print the first X results and allow for iteration.

To run your query using --eval try:

mongo myhost:myport/mydb --eval  "db.mycollection.find().forEach(printjson)"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top