【发布时间】:2018-12-25 22:14:32
【问题描述】:
我关注了来自https://github.com/Apress/def-guide-to-mongodb/tree/master/9781484211830/The%20Definitive%20Guide%20to%20MongoDB 的bson 和json 文件
$ ls .
aggregation.bson aggregation.metadata.json mapreduce.bson mapreduce.metadata.json storage.bson text.json
如何将它们导入 MongoDB?
我尝试将它们中的每一个都作为一个集合导入,但失败了:
$ mongorestore -d test -c aggregation
2018-07-18T01:44:25.376-0400 the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead
2018-07-18T01:44:25.377-0400 using default 'dump' directory
2018-07-18T01:44:25.377-0400 see mongorestore --help for usage information
2018-07-18T01:44:25.377-0400 Failed: mongorestore target 'dump' invalid: stat dump: no such file or directory
我不确定我是否正确指定了文件aggregation.bson,但上面的命令是我从书中类似示例中学到的。
谢谢。
更新
下面,为什么第一个失败,第二个成功?我应该使用哪个命令?
$ mongoimport -d test -c aggregation --file aggregation.bson
2018-07-18T09:45:44.698-0400 connected to: localhost
2018-07-18T09:45:44.720-0400 Failed: error processing document #1: invalid character 'º' looking for beginning of value
2018-07-18T09:45:44.720-0400 imported 0 documents
$ mongoimport -d test -c aggregation --file aggregation.metadata.json
2018-07-18T09:46:05.058-0400 connected to: localhost
2018-07-18T09:46:05.313-0400 imported 1 document
【问题讨论】:
-
您知道 mongo 在安装过程中提供了命令行实用程序mongoexport,这可能会对您有所帮助。
标签: mongodb