导入 BSON 文档时出错,MongoDB
Error importing BSON document, MongoDB
我正在尝试将示例 BSON 文件 test.bson
导入 MongoDB。服务器已经是运行,所以我用
mongoimport --db test --collection foo --drop --file test.bson
但是,我收到以下错误:
2016-01-24T13:51:06.126-0500 connected to: localhost
2016-01-24T13:51:06.144-0500 Failed: error processing document #1: invalid character 'è' looking for beginning of value
2016-01-24T13:51:06.144-0500 imported 0 documents
(1) 如何解决这个错误,invalid character 'è' looking for beginning of value
?我究竟应该怎么做才能访问 test.bson
中的数据?
(2) 还有其他方法可以使用MongoDB导入数据吗?如果我在 shell 中并输入
$mongo
如何导入 json/bson 文件?
(BSON 是带有附加类型信息的 JSON 的二进制表示。)
我认为您需要 mongorestore 而不是 mongoimport。所以试试
mongorestore --db test --collection foo --drop test.bson
来自文档:
WARNING:
Avoid using mongoimport and mongoexport for full instance production backups. They do not reliably preserve all rich BSON data types, because JSON can only represent a subset of the types supported by BSON. Use mongodump and mongorestore as described in MongoDB Backup Methods for this kind of functionality.
mongoimport 和 mongoexport 用于 json-like 数据表示(尽管它也适用于 CSV 和 TSV)。 mongorestore 和 mongoexport 用于 bson。
我正在尝试将示例 BSON 文件 test.bson
导入 MongoDB。服务器已经是运行,所以我用
mongoimport --db test --collection foo --drop --file test.bson
但是,我收到以下错误:
2016-01-24T13:51:06.126-0500 connected to: localhost
2016-01-24T13:51:06.144-0500 Failed: error processing document #1: invalid character 'è' looking for beginning of value
2016-01-24T13:51:06.144-0500 imported 0 documents
(1) 如何解决这个错误,invalid character 'è' looking for beginning of value
?我究竟应该怎么做才能访问 test.bson
中的数据?
(2) 还有其他方法可以使用MongoDB导入数据吗?如果我在 shell 中并输入
$mongo
如何导入 json/bson 文件?
(BSON 是带有附加类型信息的 JSON 的二进制表示。)
我认为您需要 mongorestore 而不是 mongoimport。所以试试
mongorestore --db test --collection foo --drop test.bson
来自文档:
WARNING:
Avoid using mongoimport and mongoexport for full instance production backups. They do not reliably preserve all rich BSON data types, because JSON can only represent a subset of the types supported by BSON. Use mongodump and mongorestore as described in MongoDB Backup Methods for this kind of functionality.
mongoimport 和 mongoexport 用于 json-like 数据表示(尽管它也适用于 CSV 和 TSV)。 mongorestore 和 mongoexport 用于 bson。