Home > Mobile >  Mongoexport yields 0 records when trying to export to csv with "database.collection 0"
Mongoexport yields 0 records when trying to export to csv with "database.collection 0"

Time:01-16

I'm trying to run mongoexport on my server but it yields 0 records.

Here is my script

mongoexport --db=customer --collection=transaction --type=csv --query='{"program": "online", "create_time": {"$gte": "2023-01-01 00:00", "$lt": "2023-01-02 00:00}, "amount" : {"gt": 0}}' --out=out.csv --fields=field1,field2,field3 --uri="mongodb://username:password@localhost1,localhost2/?authsSource=admin

Here is the output

2023-01-13T11:28:17.715 0700 connected to mongodb://username:password@localhost1,localhost2/?authsSource=admin
2023-01-13T11:28:17.715 0700 customer.transaction 0
2023-01-13T11:28:17.715 0700 customer.transaction 0
2023-01-13T11:28:17.715 0700 customer.transaction 0

And the result of the out.csv file is blank.

What did I miss here?

CodePudding user response:

Nevermind.. Apparently the zeros in the terminal output indicates the rows is being read. Hence my script is correct.

Here's the output if anyone curious.

2023-01-13T13:09:53.541 0700 customer.transaction 32000
2023-01-13T13:09:54.540 0700 customer.transaction 64000
2023-01-13T13:09:55.540 0700 customer.transaction 64000
2023-01-13T13:09:56.541 0700 customer.transaction 78355
2023-01-13T13:09:56.747 0700 exported 238355 records

And the output file out.csv is filled.

  • Related