I've enabled automatic backups on Mongo Atlas.
Now I need to view and query a specific snapshot to check some documents?
How can I do it quickly and safely?
Go to Mongo Atlas console, click on your cluster, then go to Backup tab and download your snapshot:
You'll get a .tgz archive. It opens in a popup, so mind your blocker.
Unpack the archive, then run
docker run -it -p 27017:27017 -v /tmp/extracted/snapshot/dir:/data/db mongo
Now you can connect to the snapshot data using a mongo client like MongoDB Compas using default connection (localhost:27017).
The accepted answer did not work for me. Alternative approach:
Download the backup from your Atlas console and extract it.
Then run the following in your Terminal:
mongod --dbpath ~/Downloads/Cluster0-2020-11-20T15-53-03.006Z
Replacing Cluster0... with your extracted folder.
Now you can connect to the snapshot data using a mongo client like MongoDB Compass using default connection (localhost:27017).
You can also define a custom port with --port
Related
I want to use docker run a vm mongodb, at the same time, the mongo configure file use my own defined configure file to archive replication and open authentication.
Scanning some files but don't resolve the problem.
Any ideas?
The docker mongo image has a docker-entrypoint.sh it calls in the Dockerfile
Check if you can:
create your own image which would create the right user and restart mongo with authentication on: see "umputun/mongo-auth" and its init.sh script
or mount a createUser.js script in docker-entrypoint-initdb.d.
See "how to make a mongo docker container with auth"
I've downloaded the production mongodb and dropped the folder with the data into my documents directory under a folder titled project1. I'm noticing that launching mongo with the following command mongod --port 3000 --dbpath ~/Documents/project/prod/ and then following that up with a mongo --port 3000 isn't causing the shell to find the database. The db itself should be called pord. Im wondering what am I not doing correctly. How does one get MongoDB to use a database that they've downloaded, its looking like specifying the local path isn't working.
The solution is to actually use mongorestore feature. The command is mongorestore -d db_name_here -c collection_name_here ~/path/to/file
This post is about backing up your meteor database
I am trying to back up my meteor database and I understand what this post is telling me to do, but I must not be in the right directory when I run the mongodump command, b/c I keep getting 'Command not found'. Or do I need to export a path?
[EDIT]
OK, now I have the binaries installed but when I run 'mongodump', I get:
couldn't connect to [127.0.0.1] couldn't connect to server 127.0.0.1:27017
... and when I run 'mongodump --host localhost:3002', I get:
couldn't connect to [localhost:3002] couldn't connect to server localhost:3002
Now what?
OK, thanks to #David Weldon, I can provide a fairly complete answer to this issue:
Backing up and restoring your local MongoDB for Meteor users (OSX)
Backup:
1) Your app must be running, so start up your Meteor server.
2) In a terminal window (NOT in the meteor mongo shell), enter: mongodump -h 127.0.0.1 --port 3001 -d meteor
This will create a 'dump' directory inside your home folder (your name under Users).
3) If you get a 'command not found' message, you probably just installed Mongo as a part of Meteor, meaning you don't have the mongo command line tools. Use a package like Homebrew to reinstall Mongo and you will have the command line tools. This will also add the correct PATH information to your system, so that it can find the tools.
Restoring:
1) From MiniMongo shell (run ‘meteor mongo’ inside your Meteor project dir), enter:
db.[collectionName].drop(); //repeat for all collections you wish to restore
2) Then, from a terminal window, enter:
mongorestore -h 127.0.0.1 --port 3001 -d meteor dump/meteor
Caveats:
The individual documents will not necessarily be in the same order after they are restored. So you need some way to sort documents that need to be presented in a certain order.
Caveats:
The individual documents will not necessarily be in the same order after they are restored. So you need some way to sort documents that need to be presented in a certain order.
There is a flag for this
mongorestore --maintainInsertionOrder
If you are restoring to a mup'ed meteor app, the command would be:
mongorestore -h 127.0.0.1 --port 3001 -d dump/meteor
If you forgot the name of your app, you can see it by going into the mongo shell and listing all databases.
When I create a meteor app, where is the database?
I have an app called leaderboard, but when I run mongo shell and do show dbs I see only local (empty) and test but test doesn't doesn't have the same contents as my leaderboard app. Where does meteor create the Mongo database and how can I access it from mongo shell (so I can load some data into it)?
You need to be running the application with the meteor run command in one session, at which point you can run mongo meteor in another session on the same machine, which will include something like
[kfullert#shotgun ]$ meteor mongo
MongoDB shell version: 2.2.1
connecting to: 127.0.0.1:3002/meteor
At that point, you can use the URL in the "connecting to" line with the standard mongo tools (caveat - you need to be running your project with meteor at the same time, as "meteor run" is what spins up the mongo server for your project
[kfullert#shotgun ]$ mongo 127.0.0.1:3002/meteor
MongoDB shell version: 2.2.3
connecting to: 127.0.0.1:3002/meteor
>
For mongoimport, you'll probably want something like:
[kfullert#shotgun ]$ mongoimport -h 127.0.0.1 --port 3002 -d meteor
Additionally, it may be possible to run mongoimport without meteor running, by using the following switch from your project root directory (untested so beware)
mongoimport --dbpath .meteor/local/db -d meteor
For apps running a local db server, APPDIR/.meteor/local/db
You can connect to your app's mongodb with meteor mongo and then us show collections to list the Meteor.Collections you've created.
I want to create a new database in Mongo. However, I'm having trouble connecting:
:~$ mongo
MongoDB shell version: 1.6.5
connecting to: test
Tue Dec 21 18:16:25 Error: couldn't connect to server 127.0.0.1 (anon):1154
exception: connect failed
How can I connect to mongo in order to create a new database? Alternatively, can I create a new database from the command line?
Slightly surprisingly, the Mongo docs don't seem to cover how to create a database.
Thanks.
In order to open Mongo JavaScript shell, a Listener should be initialized first.
So, first run mongod.exe before running mongo.exe. Both are in the same location(/bin).
There is no separate commands to create a db in mongodb. Just type "use dbname;" in console. Now you have created a db of the name 'dbname'. Now, if you type 'show databases' you cannot see the db name you just created. Because, mongo will not create any db, util you create collection and insert a document into that collection.
Hope this is useful to you!
cd /var/lib/mongodb/
remove mongod.lock file from this folder
sudo start mongodb (in console)
mongo (in console)
And it runs fine.
First you'll need to run mongod on one terminal. Then fire up another terminal and type mongo. This shall open the mongo shell. You also need to create /data/db/ where mongo will store your databases.
You'll need to run mongod (the daemon) before you can use mongo (the client), it's easiest to just run it in another shell; These should be in your path if mongo is installed correctly. After that the docs should get you through creating and editing dbs and collections.
Just try following commands in given order :
sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --repair
sudo service mongodb start
sudo service mongodb status