mongodb - 带有从属数据库查询的 mongodump

标签 mongodb mongodump

我正在尝试从辅助设备转储,这样就不会影响实时流量。

我可以成功地从中转储。但如果我添加一个查询,我会得到 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/

相关文章:

javascript - Mongodb 从 ObjectId 获取 3 字节计数器

javascript - 使用 Mongoose 中对象数组的循环保存模型。全部插入后需要回调

java - 使用求和和排序进行 mongodb 查询的最佳方法是什么

node.js - 如何从 Nodejs 应用程序容器使用 mongodump 命令?

Windows 上的 Mongodb 数据库备份

mongodb - 如何将 nitrous.io 框中的 mongodb 二进制文件更新为 2.4.x 版本?

node.js - 在 Mongoose 中添加多个验证

node.js - Sails 在两个模型中插入相同的对象

MongoDB从3.6升级到4.0 : How to fix the "collection does not have uuid in kvcatalog" exception?

mongodb - 从谷歌云存储流恢复 `mongodump`备份