-1

I exported the collections from a local database and I want to import them into an ec2 instance.

I did the following:

1) I exported the collections to a folder called data. The files are in this format:

collecion_test.bson

collection.metadata.json

2) I transferred the folder to an ec2 instance. The path to access the folder is like this:

/home/ec2-user/data

3) I went into mongo and did "use database_test" and created a collection like this: db.createCollection("data")

Finally, I tried to import the file this way:

mongoimport --db database_test --collection data --file /home/ec2-user/data/data.metadata.json -jsonArray

but I get this error:

2022-02-18T19:29:38.380+0000 E QUERY [js] SyntaxError: missing ; before statement @(shell):1:14

I appreciate if anyone can help me analyze this!

E. Biagi
  • 452
  • 3
  • 12

1 Answers1

1

The problem is that you used mongodump which created the xxx.bson and xxx.meta.json so you need to use mongorestore to read those files. Use mongoimport to read files created with mongoexport

for a full explanation see https://docs.mongodb.com/database-tools/

In short mongodump/mongorestore deal with bson files while mongoexport/mongoimport work with csv/tsv/json files. So for example one neat thing about these commands, is if you supply an optional -q parameter like {field:x} then only the records that filter would select will be used in the dump.

Ilan Toren
  • 50
  • 6
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Pankwood Feb 21 '22 at 02:58
  • I used this mongorestore command: mongorestore -d db_name -c collection_name /path/file.bson but it does not work! – – E. Biagi Feb 21 '22 at 13:09
  • What is missing is an example of what the proposed input is. A jsonArray is [ {}, {}], but there is also a format where each line is a {}, so it helps to know what command was used to create the file you want to import. – Ilan Toren Mar 20 '22 at 08:22