Export and Import Mongodb from Meteor APP - mongodb

How is it possible to Import and export the MongoDB from Meteor APP into .json or .csv file ?

You can use mongoexport utility to export into a .json or .csv file and mongoimport to import to your db. Detailed info is found here: http://docs.mongodb.org/v2.2/reference/mongoexport/

If you intend to reimport into mongodb, mongodump might be a bit better since you won't be losing type information
Try mongodump
mongodump --host 127.0.0.1:3001
Here you get BSON, and separate key indexes in json files. Then you can use the dumps to restore your db (if this is your intention):
If you're in the dump directory from above:
mongorestore --host 128.199.224.29:27017 --db meteor .

Related

Error importing collections into a mongodb database on an ec2 instance

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.

How to export the database of the mongodb with gzip file extension

I'm using mongodb for saving the data for my application and I want to backup of that database in gzip file I searched for it and I found question posted by the other users
link https://stackoverflow.com/questions/24439068/tar-gzip-mongo-dump-like-mysql
link https://stackoverflow.com/questions/52540104/mongodump-failed-bad-option-can-only-dump-a-single-collection-to-stdout
I used these commands but that will not me the expected output I want the command that will create my database gzip compress file and using extraction I will restore that database folder into the mongodb
currently I'm using this below command
mongodump --db Database --gzip --archive=pathDatabase.gz
which will create a compression of .gz while I extract it it will show me nothing.
Can you please give me a command that I will use it or any suggestions will appreciated.
When you use mongodump --db Database --gzip --archive=pathDatabase.gz You will create 1 archive file (it does not create a folder) for the specified DB and compress it with gzip. Resulting file will be pathDatabase.gz in your current directory.
To restore from such file, you'd do this
mongorestore --gzip --archive=pathDatabase.gz
This will restore the db "Database" with all its collection.
You can check out these MongoDB documentation pages for more info
Dump: https://docs.mongodb.com/manual/reference/program/mongodump/
Restore: https://docs.mongodb.com/manual/reference/program/mongorestore/
Edit: Removed --db flag from restore command as it is not supported when used with --archive.
mongodump --archive=/path/to/archive.gz --gzip will actually create an archive which interleaves the data from all your collections in a single file. Each block of data is then compressed using gzip.
That file can not be read by any other tool than mongorestore, and you need to use identical flags (i.e. mongorestore --archive=/path/to/archive.gz --gzip), which you can use to restore your dump on another deployment.
The resulting archive can not be extracted using gunzip or tar.
If you need to change the target namespace, then you should use the --nsFrom, --nsTo and --nsInclude options in order to use a different database name.

How to migrate RethinkDb into MongoDb?

My application is using RethinkDb. Everything is running fine, but a new required needs to migrate the db into MongoDb.
Is this possible? How do I migrate the tables/collections, data, indexes, etc?
How about blob types, auto increments. ids?
Thanks!
Is this possible? How do I migrate the tables/collections, data, indexes, etc?
One way to migrate data from RethinkDB to MongoDB is to export data from RethinkDB using rethinkdb dump command, and then use mongoimport to import into MongoDB. For example:
rethinkdb dump -e dbname.tableName
This would generate an archive file:
rethinkdb_dump_<datetime>.tar.gz
After uncompressing the archive file, you can then use mongoimport as below:
mongoimport --jsonArray --db dbName --collection tableName ./rethinkdb_dump_<datetime>/dbName/tableName.json
Unfortunately for the indexes, the format between RethinkDB and MongoDB is quite different. The indexes are stored within the same archived file:
./rethinkdb_dump_<datetime>/dbName/tableName.info
Although you can still write a Python script to read the info file, and use MongoDB Python driver (PyMongo) to create the indexes in MongoDB. See also create_indexes() method for more information.
One of the reasons in suggesting to use Python, is because RethinkDB also has a Client Python driver. So technically, you can also skip the export stage and write a script to connect your RethinkDB to MongoDB.

Exporting specific gridfs files from MongoDB

I have large number of files in database,I need to take backup of specific week files and export to another database.I can dump fs.files based on uploadDate.
./mongodump --port <port> --db <Database> --collection fs.files --query <json> --out <destination>
How can I export the specific fs.chunks data while iterating fs.files in the shell?
Here's a blog post and the gist for a bash script that will do what's asked for here. Run this script from the command line of the mongodb server. It will loop through the fsfiles collection and exporting the files using the mongofiles utility that is included with MongoDB.
Original Blog Post
Gist

Could not export whole database using MongoDB in Ubuntu

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>