How can I copy a db mongo to another mongodb instance? [duplicate] - mongodb

This question already has answers here:
How do I copy a database from one MongoDB server to another?
(5 answers)
Closed 4 years ago.
I want to copy my db called users binded by default to localhost:27017 to another bind address. How can I do this?

You could try using this copydb command.
Otherwise, you could use mongo export, export the data to a file. Then import those data into the new database. Back Up and Restore with MongoDB Tools
Here is the doc of mongo export
mongoexport

Related

Why doesn't my created DB show up when I doe show databases in mongo? [duplicate]

This question already has an answer here:
Mongo: show dbs doesn't show the test db. Why?
(1 answer)
Closed 3 years ago.
I tried going into a mongo shell and creating a DB, and it seems to have worked, its saying I'm in the db i created but when I run show databases; it doesnt show in the list.
Here is what terminal shows:
> show databases;
admin 0.000GB
config 0.000GB
local 0.000GB
> use sr-dev
switched to db sr-dev
> show databases;
admin 0.000GB
config 0.000GB
local 0.000GB
> db
sr-dev
>
Mongo only creates databases and collections as needed, as lazily as possible. You didn't "create" sr-dev, you're merely "using" it at the moment. Think of it as "being in the namespace sr-dev". Once you insert your first data the actual database will be created. Before you do that, there's no need for it to exist.
Create a Database
If a database does not exist, MongoDB creates the database when you first store data for that database. As such, you can switch to a non-existent database and perform the following operation in the mongo shell: [..]
https://docs.mongodb.com/manual/core/databases-and-collections/#create-a-database
When you create a database in MongoDb shell, it won't show up until there are some collections in your database.
Please try adding some collections in your newly created database and run show databases command again, It will show up.
db.createCollection('collection_name',{...})
Here the 2nd parameter is optional.
Please read MongoDb createCollection documentation for more info, on 2nd parameter options.
You will have to create collection inside your db.
MongoDB works this way.

Postgreql: adding database by its files [duplicate]

This question already has answers here:
How to restore PostgreSQL dump file into Postgres databases?
(8 answers)
How restore postgreSQL dump file using pgAdmin?
(1 answer)
How to backup & Restore PostgreSQL database in Windows7?
(3 answers)
How to restore table from dump to database?
(1 answer)
Is it possible to restore a Postgres database by simply swapping out some files for speed?
(2 answers)
Closed 4 years ago.
I have copied database folder from data/base and I wanted to copy them in another computer but in pgAdmin can't find the new database should I do something else besides copying the folder in data/base?
I'm using PostgreSQL 9.3
The problem is that when I try to save database from pgAdmin it freezes, I'm not sure if the database is corrupted or some tables.

mongorestore not working after mongodump [duplicate]

This question already has answers here:
Mongodb monogorestore "root directory must be a dump of a single database"
(2 answers)
Closed 6 years ago.
I am using a mongodb with version:2.4.14
I have used the below command to dump a database named masters
mongodump -d masters -o /var/www/html/test/dbbackup
It runs successfully and in dbbackup folder i got so many files with the collection name with type .json and .bson
Now when I am trying to restore the db using the following command
mongorestore -d testdatabase1 /var/www/html/test/dbbackup/
I am getting the following error:
ERROR: root directory must be a dump of a single database
ERROR: when specifying a db name with --db
You have to include the original database name in the path as :
mongorestore -d testdatabase1 /var/www/html/test/dbbackup/masters

MongoDB migration

Hello I have an ubuntu 14.04 server that is running mongodb 2.4.14. I need to move the mongo instance to a new server. I have installed mongo 3.4.2 on the new server and need to move the databases over. I am pretty new with mongo. I have 2 databases that are pretty big but when I do a mongo dump the file is nowhere near the site of the databases that mongo is showing.I cannot figure out how to get mongoexport to work. What would be the best way to move those databases? If possible can we just export the data from mongo and then import it?
You'll need to give more information on your issue with mongodump and what mongodump parameters you were using.
Since you are doing a migration, you'll want to use mongodump and not mongoexport. mongoexport only outputs a JSON/CSV format of a collection. Because of this, mongoexport cannot retain certain datatypes that exist in BSON and thus MongoDB does not suggest that anyone uses mongoexport for full backups; this consideration is listed on mongo's site.
mongodump will be able to accurately create a backup of your database/collection that mongorestore will be able to restore that dump to your new server.
If you haven't already, check out Back Up and Restore with MongoDB Tools

Meteor -- How to connect to mongodb? [duplicate]

This question already has answers here:
How do I use an existing MongoDB in a Meteor project?
(8 answers)
Closed 7 years ago.
I am new to meteor platform.
I have created a meteor project.
Need help to change db. I have created a mongodb in https://mongolab.com/. It provided connection string and I am able to successfully connect to that DB from terminal(Ubuntu).
I want to connect to mongodb hosted in https://mongolab.com/. How can I update connection string in meteor project?
Thanks in advance
Export the MONGO_URL environment variable with the MongoLab connection string like this export MONGO_URL=mongodb://localhost:27017/your_db
Then, run meteor as usual.