I am learning MongoDB and for practice i downloaded the restaurant data from mongodb site. I am using windows OS and mongo is installed properly.
Now, I want to insert all the restaurant documents ( i.e json data) to mongodb. I am using cmd and tried this command
mongoimport --db test --collection restaurants --drop --file ~/downloads/primer-dataset.json
but it failed and got the message that
SyntaxError: missing ; before statement #(shell):1:4
How to solve this error? Please help me because I couldn't find satisfactory answer even after spending too much time.
mongoimport must be run from the Windows command prompt, not the mongo shell.
Related
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!
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.
I have installed Mongodb following the instruction. However, it only has Mongo in usr/local/bin
When I tried to import a json file into my database, it showed an error message:
> mongoimport --jsonArray --db hw4 --collection restaurants --file restaurants.json
2019-11-12T15:18:28.737-0600 E QUERY [js] uncaught exception: SyntaxError: unexpected token: identifier :
#(shell):1:14
It seems there's no mongoimport installed. How could I install it, or is there another way to import data?
The --jsonArray option provided with command could be causing the issue, is probably not required. What does restaurants.json look like?
mongoimport should be run from the shell command line, not from inside the mongo shell.
To ensure the correct installation of MongoDB and its associated tools, please follow the procedure outlined in Install MongoDB Community Edition on macOS
Hello I have an ubuntu 14.04 server that is running mongodb 2.4.14. I need to move the mongo instance to a new server. I have installed mongo 3.4.2 on the new server and need to move the databases over. I am pretty new with mongo. I have 2 databases that are pretty big but when I do a mongo dump the file is nowhere near the site of the databases that mongo is showing.I cannot figure out how to get mongoexport to work. What would be the best way to move those databases? If possible can we just export the data from mongo and then import it?
You'll need to give more information on your issue with mongodump and what mongodump parameters you were using.
Since you are doing a migration, you'll want to use mongodump and not mongoexport. mongoexport only outputs a JSON/CSV format of a collection. Because of this, mongoexport cannot retain certain datatypes that exist in BSON and thus MongoDB does not suggest that anyone uses mongoexport for full backups; this consideration is listed on mongo's site.
mongodump will be able to accurately create a backup of your database/collection that mongorestore will be able to restore that dump to your new server.
If you haven't already, check out Back Up and Restore with MongoDB Tools
I use mongochef as a UI client for my mongo database. Now I have collection which consists of 12,000 records. I want to export them using the mongochef.
I have tried with the export option(available) which is working fine up to 3000 documents. But if the number of records gets increasing the system is getting hung up.
Can you please let me know the best way to export all the documents in a nice way using mongochef.
Thanks.
Finally I came to conclusion to use the mongo using terminal which the best way to use(efficient).
read about the primary and secondary databases and executed the following query:
mongoexport --username user --password pass --host host --db database --collection coll --out file_name.json
I need one help. I need to export and import the total database/all collection for MongoDB using Ubuntu. I am explaining my command below.
sudo mongoexport --db FGDP --out /home/subrajyoti/Downloads/newdbexport.json;
Here i am getting the following error message.
2016-12-22T10:28:46.290+0530 error validating settings: must specify a collection
2016-12-22T10:28:46.290+0530 try 'mongoexport --help' for more information
Here i need to export all collection rather than one single one. Please help me.
Exporting all collections of all database using mongodump use the following command:
mongodump -o <directory_backup>