Restoring a mongo database but mongo shell does not show it - mongodb

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).

Related

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/

mongodump references wrong db directory

I had an install of MongoDB that was using on OSX that was using ~/data/db. I had a crash and re-installed MongoDB using Homebrew and it set up the new db path at ~/usr/local/var/mongodb.
All of my apps are working (default port 27017), but when I try to run mongodump it backs up the db in ~/data/db which is now out of date.
How can I get mongodump to reference the correct db folder?

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.

where is the mongodb database when the meteor instance is not running

In Meteor, each new application I create, it creates a new MongoDb instance and when I run the instance by typing "meteor" it is available until I stop Meteor.
I can save data etc. into this mongodb and the next time I boot up meteor, it should appear again.
So I'm just wondering, where are these mongodbs being stored? how can I access one when I don't have the meteor server running?
The actual data files are stored under the project directory under the path .meteor/local/db, so it really is just a matter of starting up an independent instance when your meteor server is not running:
$:~/myapp$ mongod --smallfiles --dbpath .meteor/local/db --port 30000
And of course with port and/or IP binding that does not conflict with another instance, and of course without the meteor process having started a mongod instance on this data already.
But you are probably better off just defining an external server to your project and just running that separately. Just define the environment variable so the startup process knows which mongodb instance to use:
export MONGO_URL=mongodb://your_host:27017/your_db
Or otherwise essentially replacing your_host and possibly the port as well as your_db with the target details of the server and database you want to use.

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).