使用 mongoexport 查询 req.user.id
Query using mongoexport for req.user.id
我正在尝试导出名为 asset-management
的数据库以及 req.user.id
的所有集合,但 users
集合除外。我似乎无法让下面的工作。
mongoexport --db asset-management --collection * --type=csv --query '{"author.id": req.user.id}' --out userbackup.csv
我收到此错误消息:
解析命令行时出错:未知选项类型
在 Mongo 2.6 中,这应该可以工作:
mongoexport --db asset-management --csv --query "{'author.id': 'req.user.id'}" --fields \"fieldNameA,fieldNameB\" --out userbackup.csv
这个和你问题中的mongoexport
命令的区别是:
交换了 --query
参数中的 "
和 '
,以解决“解析命令行时出错:太多位置选项”
已删除 --collection *
这看起来像是意在表示 所有集合 在这种情况下它是多余的,因为这是默认行为。在你的问题中你说:“我正在尝试导出一个名为资产管理的数据库和所有 req.user.id 的集合,除了用户集合”,这在使用 mongoexport
时是不可能的......你可以导出特定集合或所有集合,但您不能将单个集合列入黑名单
添加 --fields
因为根据 to the docs ...
If you specify --csv, then you must also use either the --fields or the --fieldFile option to declare the fields to export from the collection.
我正在尝试导出名为 asset-management
的数据库以及 req.user.id
的所有集合,但 users
集合除外。我似乎无法让下面的工作。
mongoexport --db asset-management --collection * --type=csv --query '{"author.id": req.user.id}' --out userbackup.csv
我收到此错误消息:
解析命令行时出错:未知选项类型
在 Mongo 2.6 中,这应该可以工作:
mongoexport --db asset-management --csv --query "{'author.id': 'req.user.id'}" --fields \"fieldNameA,fieldNameB\" --out userbackup.csv
这个和你问题中的mongoexport
命令的区别是:
交换了
--query
参数中的"
和'
,以解决“解析命令行时出错:太多位置选项”已删除
--collection *
这看起来像是意在表示 所有集合 在这种情况下它是多余的,因为这是默认行为。在你的问题中你说:“我正在尝试导出一个名为资产管理的数据库和所有 req.user.id 的集合,除了用户集合”,这在使用mongoexport
时是不可能的......你可以导出特定集合或所有集合,但您不能将单个集合列入黑名单添加
--fields
因为根据 to the docs ...If you specify --csv, then you must also use either the --fields or the --fieldFile option to declare the fields to export from the collection.