Exporting specific gridfs files from MongoDB - 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

Related

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.

Where mongoimport store the document in a Docker container

So I'm searching where the files are stored after this command
mongoimport --db meteor --collection articles --type csv --headerline --file /data/seeds/articles.csv
I'm using a Docker container from the image mongo:latest
I thought it would be in the /data/db but there isn't my db 'meteor' or my collection 'articles' so I think I'm not in the right folder...
(The application is working perfectly, the data are displayed on the website)
Someone can help me ?
MongoImport imported the csv data into db collection articles.
You will now have to connect to mongod server through mongo shell and run the below commands.
Switch to the db meteor
Use meteor
View collection article
db.article.find()

Mongo compare and import missing data

I have a mongo server receiving data from servers behind an amazon LB, 2 days ago there was an error and part of the servers sent their data to an old mongo server that had a db of the same name, we realized that and fixed it back right away.
Now i have part of my data stored on the wrong machine.
What I need now is a way to compare the data between the 2 dbs (which each have 2 relevant collections) and insert only the missing data to the correct collection.
I do not care about the unique id mongo gives but i do need to compare by the field "uuid" that we create.
mongo version: 2.4.4
I am new to Mongo and any help would be greatly appreciated.
Yes, you can. Follow these steps...
1 mongoexport and then mongoimport on the basis of fields on which you want to compare and import.
mongoexport --db db_name --collection collection_name --type csv --fields field1,field2,field3 --out /var/www/export.csv
once you get the exported CSV at the specified location. Open and remove unwanted fields...
mongoimport --db db_name --collection collection_name --type csv --file /var/www/export.csv --fields field1,field2,field3 --upsertFields field1,field2,field3
NOTE:
1. If you working in production environment, dealing with huge database then free up your mongo from load of queries and then export else it might get stucked.

Importing large number of records in json file to mongodb

I just started learning to build nodejs application. I am able to figure how things work so i made decision to test my application with large test data.
I create json file with 1 million records in it.
I import data using
mongoimport --host 127.0.0.1 --port 27017 --collection customers --db Customer --file "path to json file mock.json" --jsonArray
Sample Json file is
[{"fname":"Theresia","lname":"Feest","email":"aileen#okeefe.name"},
{"fname":"Shannon","lname":"Bayer","email":"tristian.barrows#christiansenvandervort.com"},
{"fname":"Cora","lname":"Baumbach","email":"domenico.grimes#lesley.co.uk"},
{"fname":"Carolina","lname":"Hintz","email":"betty#romaguerasenger.us"},
{"fname":"Dovie","lname":"Bartell","email":"rogers_mayert#daniel.biz"}]
but it is taking too much time approx. 14 Hrs.
Please suggest any other optimized ways for the same.
Split your single json file into multiple files and then run multiple parallel mongoimport commands for each of the file.

Export and Import Mongodb from Meteor APP

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 .