admin管理员组

文章数量:1415684

I am trying to import a sample BSON file test.bson into MongoDB. The server is already running, so I use

mongoimport --db test --collection foo --drop --file test.bson

However, I get the following error:

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) How does one get around this error, invalid character 'è' looking for beginning of value? What exactly should I do to access the data in test.bson?

(2) Is there any other way to import data using MongoDB? If I am in the shell and type

$mongo

how can I import json/bson files?

(BSON is a binary representation of JSON with additional type information.)

I am trying to import a sample BSON file test.bson into MongoDB. The server is already running, so I use

mongoimport --db test --collection foo --drop --file test.bson

However, I get the following error:

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) How does one get around this error, invalid character 'è' looking for beginning of value? What exactly should I do to access the data in test.bson?

(2) Is there any other way to import data using MongoDB? If I am in the shell and type

$mongo

how can I import json/bson files?

(BSON is a binary representation of JSON with additional type information.)

Share Improve this question edited Jan 24, 2016 at 18:58 ShanZhengYang asked Jan 24, 2016 at 18:53 ShanZhengYangShanZhengYang 17.7k52 gold badges142 silver badges247 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 6

I think you need mongorestore instead of mongoimport. So try

mongorestore --db test --collection foo --drop test.bson

From the docs:

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 and mongoexport are used with json-like representations of the data (although it also works with CSV and TSV). mongorestore and mongoexport are for bson.

本文标签: javascriptError importing BSON documentMongoDBStack Overflow