我正在尝试从辅助设备转储,这样就不会影响实时流量。
我可以成功地从中转储。但如果我添加一个查询,我会得到 0 个文档。
我需要添加什么才能成功查询我的从站?
0 Documents:
mongodump --host xxxx --port 27017 --username xxx --password xxx --db test --collection xxxx --query "{date_visited:{'$gte':new Date(1451606400000)}}" --out /dumps/xxxx-after-2016-01-01.json
All Documents:
mongodump --host xxxx --port 27017 --username xxx --password xxx --db test --collection xxxx --out /dumps/xxxx.json
最佳答案
像这样尝试,即交换双引号和单引号的用法,以避免 shell 进行任何评估,如 docs 中所述。
--query , -q
Provides a JSON document as a query that optionally limits the documents included in the output of mongodump.
You must enclose the query in single quotes (e.g. ') to ensure that it does not interact with your shell environment.
mongodump --host xxxx --port 27017 --username xxx --password xxx --db test --collection xxxx --query '{date_visited:{"$gte":new Date(1451606400000)}}' --out /dumps/xxxx-after-2016-01-01.json
关于mongodb - 带有从属数据库查询的 mongodump,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39630450/