Mongodump with --query date

Hello,

I’m trying to do a mongodate with date range:

mongodump --port 27005 --db phoenix --collection audit_log --query ‘{“timestamp” :{ “$gte”: { “$date”: “2020-01-01T00:00:00.000Z” } } }’ --out /mnt/backup/mongodump/

But output is:

2021-06-02T18:06:29.958+0200    writing phoenix.audit_log to /mnt/backup/mongodump/phoenix.dmp/phoenix/audit_log.bson
2021-06-02T18:06:32.211+0200    phoenix.audit_log  0
2021-06-02T18:06:35.211+0200    phoenix.audit_log  0
2021-06-02T18:06:38.211+0200    phoenix.audit_log  0
2021-06-02T18:06:41.211+0200    phoenix.audit_log  0
2021-06-02T18:06:44.211+0200    phoenix.audit_log  0
2021-06-02T18:06:47.211+0200    phoenix.audit_log  0
2021-06-02T18:06:50.211+0200    phoenix.audit_log  0
2021-06-02T18:06:53.211+0200    phoenix.audit_log  0
2021-06-02T18:06:56.211+0200    phoenix.audit_log  0
2021-06-02T18:06:59.211+0200    phoenix.audit_log  0
2021-06-02T18:07:02.211+0200    phoenix.audit_log  0
2021-06-02T18:07:05.211+0200    phoenix.audit_log  0
2021-06-02T18:07:08.211+0200    phoenix.audit_log  0
2021-06-02T18:07:11.211+0200    phoenix.audit_log  0
2021-06-02T18:07:14.211+0200    phoenix.audit_log  0
2021-06-02T18:07:17.211+0200    phoenix.audit_log  0
2021-06-02T18:07:20.211+0200    phoenix.audit_log  0
2021-06-02T18:07:23.211+0200    phoenix.audit_log  0
2021-06-02T18:07:26.211+0200    phoenix.audit_log  0

and still running.

The collection was created at 2016, could you confirm if mongodump is checking all documents and it will write when arrive to 2020?

Thanks in advance.

Regards

Hi @Agus_Luesma, it does look like this query is doing a collection scan. Do you have an index on the timestamp field? If there is no index that the query can use, it will have to check all documents which is inefficient. You can see here for more information on indexes: https://docs.mongodb.com/manual/indexes/

1 Like