empty output of mongodump - mongodb

I have app running against local mongo on server with ip xxx.xxx.xxx.xx. I would like to dump data using mongodump. I ssh to the server. First i checked if mongo is running are data are there. I did mongo and show dbs, I see list of dbs. Now I did use app and show collections data are there. So I tried mongodump --db app and I see in console
connected to: 127.0.0.1
2021-10-28T11:12:03.321+0000 DATABASE: app to dump/app
Great, but only thing it did, it created dump/app folder. But folder is unfortunately empty. What I do wrong?

Related

Restoring a mongo database but mongo shell does not show it

mongodump was used long time ago to create a backup, now in order to restore the database for a Meteor app, this command was used:
ais2> mongorestore C:\Users\AAA\Documents\meteor\apps\dump\dump\
PS C:\Users\empl1\Documents\meteor\apps\ais2> mongorestore C:\Users\AAA\Documents\meteor\apps\dump\dump\
preparing collections to restore from
reading metadata for dbais2.dataTeckAllMatchCol from C:\Users\AAA\Documents\meteor\apps\dump\dump\dbais2\dataTeckAllMatchCol.metadata.json
reading metadata for dbais2.makeModelCol from C:\Users\AAA\Documents\meteor\apps\dump\dump\dbais2\makeModelCol.metadata.json
reading metadata for dbais2.usageCol from C:\Users\AAA\Documents\meteor\apps\dump\dump\dbais2\usageCol.metadata.json
reading metadata for dbais2.vehiclesDetailsCol from C:\Users\AAA\Documents\meteor\apps\dump\dump\dbais2\vehiclesDetailsCol.metadata.json
restoring dbais2.dataTeckAllMatchCol from C:\Users\AAA\Documents\meteor\apps\dump\dump\dbais2\dataTeckAllMatchCol.bson
restoring dbais2.makeModelCol from C:\Users\AAA\Documents\meteor\apps\dump\dump\dbais2\makeModelCol.bson
restoring dbais2.usageCol from C:\Users\AAA\Documents\meteor\apps\dump\dump\dbais2\usageCol.bson
restoring dbais2.vehiclesDetailsCol from C:\Users\AAA\Documents\meteor\apps\dump\dump\dbais2\vehiclesDetailsCol.bson
finished restoring dbais2.dataTeckAllMatchCol (11705 documents, 0 failures)
Since I have a directory "dbais2" with all the database files located in the above path.
In a new shell ais2> meteor mongo opens a mongo shell, but show dbs does not show the "dbais2". How can I use the newly restored database? or it was not restored correctly? if so. how to restore it correctly?
Thanks
When you run mongorestore as is, it will connect to the mongo instance running on port 27017 on your local machine (if any). That's what you would use in production. Since the restore succeeded, it must be that you have such an instance running. In that case, run mongo ais2 to connect to that instance and db.
In development, meteor runs its own mongo instance on port 3001 (assuming you used meteor on the default port 3000). When you run meteor mongo that is the instance your shell will connect to. If you want to restore into that, then rerun your command with the port specified:
mongorestore --port=3001 -d meteor C:\Users\AAA\Documents\meteor\apps\dump\dump\
After that you should see your data in the shell opened by meteor mongo. Note that in this command I'm also overriding the database name, so that the data will be imported into the database used by meteor in development (also called meteor).

mongorestore collections with metoer running on local windows 10

I have a dump folder which was created few year ago using mongodump, and want to use this info with a newly created metor app which is the same as the old meteor app after few packages updates and runs without errors.
I installed the mongodb server on this windows 10, the cmd mongo prints
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
MongoDB server version: 4.2.7
what is the "best" way to use the info with the meteor app.
Can some one please give the overview of how all this things work together and then how to use the old info "including the command mongorestore" with the newly created metoer app?
It has been few years so will need polish my thinking on meteor and mongodb again.
My understanding is mongorestore the backup, then run the mongodb server in a separate cmd window, issue a cmd to connect to the restored database, and somehow tell meteor to use this server. Ok I give up.
Thanks
Meteor comes with a bundled MongoDB in development mode, where the mongodb always runs on the app's port + 1 (app: 3000 = mongo: 3001).
You can simply start your Meteor app and when running open a new console and cd into your project folder, then enter:
mongorestore -h localhost:3001 --db meteor /path/to/dump/

MongoDB: mongorestore failing for small database

I am setting up a Mongo DB database on mongolab. I have 2 small documents in a single collection in my local db server, that I want to upload. I used mongodump to export that to a collection.bson and collection.metadata.json file
When I use mongorestore I get an error:
Failed:database.collection: error restoring from /tmp/mongodump/database/collection.bson: insertion error: EOF
collection.bson is less than 2KB. My research shows that this error shows up when your database is huge, but not very small. I can't get anything for my situation. The common solution of using --batchSize 1 results in the same issue.
After I run mongorestore the collection does exist on the remote, but it is empty (0 documents)
How can I get my tiny local db up on my remote server (on MongoLab).
I am locally running mongo3.4, but my MongoLab instance is 3.2.13. I'm wondering if the problem is the mismatch of versions?
mongorestore command:
mongorestore -h ds111882.mlab.com:11882 -d database -u username -p password /tmp/mongodump/database
mongodump
mongodump -d database -o /tmp/mongodump
Additional info: I imported the mongodump I created into another local database (also running 3.4) and it worked just fine, but restoring to the mongolab server causes the error.
Also a bsondump of the generated collection.bson file creates a json file with the correct 2 documents.
Found the answer, it is an issue with versions. My schema was using the Decimal128 type, which isn't supported in 3.2. Downgrading to Double (didn't need Decimal128 anyway) fixed the issue.

Import Mongo Database to local meteor application

I've downloaded a backup of a Mongo database from a production application I have hosted on Mlab.com
I want to import that database to my local meteor application so I can test some changes to the architecture of the collections on the real application data without breaking the production app.
Is there a way to do this?
Much appreciated
You will need to install Mongo locally on your machine to get the utilities you need, which is basically mongorestore. The command will look something like this:
sudo mongorestore --db newdb --drop /var/backups/mongobackups/01-20-16/newdb/
Meteor can connect to your database using this environment variable:
MONGO_URL=mongo://localhost:27017/newdb
There is an article about it for more detail here: https://www.digitalocean.com/community/tutorials/how-to-back-up-restore-and-migrate-a-mongodb-database-on-ubuntu-14-04

Restore a mongodb in meteor production server

I'm trying to copy all the data from my localhost default meteor mongo database to the production server to use it in "app.meteor.com".
I tried to use mongorestore usinng the information provided by "meteor mongo --url app.meteor.com", but it does not modify any document.
Moreover, when I connect to mongo database of the server, I can only read (find) documents. When i use update or insert functions it says "not master"
Run
~/meteor/meteor mongo -U yoapp
You will get something like this
mongodb://client:387shff-fe52-07d4-69a4-ba321f3665fe7#c0.meteor.m0.mongolayer.com:27017/yoapp_meteor_com
Take the values and put into mongorestore like this
mongorestore -u client -p 387shff-fe52-07d4-69a4-ba321f3665fe7 -h c0.meteor.m0.mongolayer.com:27017 -db yoapp_meteor_com /home/user/dump/yoapp
I just dumped a prod app to my local dev machine. Testing some new changes. Pushed code to a staging install on meteor.com and then used mongorestore to populate the staging database.
Moreover, when I connect to mongo database of the server, I can only read (find) documents. When i use update or insert functions it says "not master"
It's probably because the server you are connecting to is not a MASTER, but a SLAVE in a replica-set. Slaves are readonly and all writes need to be directed to the master. You can get the master hostname:port by querying rs.conf() and looking at the entries in members. See http://docs.mongodb.org/manual/reference/replica-configuration/
Get the master and then try mongoimport/mongorestore on it.
You should also tail the mongod logs on your production server, to see if there are any errors on import (provided you have access).