Can MongoDB databases be stored in different directories? - mongodb

I'm having trouble figuring out the answer to this one:
Am I supposed to run one instance of MongoDB for each directory location?
Or am I supposed to store all databases in the same location?
Or Do I run one MongoDB instance and can specify a different location for each database at run time?

You can use the --directoryperdb option of mongodb to store each DB in a different physical location.

Related

How to specificy path of new collection in Mongo DB?

I am running Mongo on Windows 10. Data access is made trugh Pymongo (Python). All my data is stored in an old large HDD, but I would like to have some smaller collection stored on a much faster SSD? When I create a new collection either trough Compass or Pymongo there is no option to specify the path on disk.
Is it possible to learn such power?
If you want to have databases in different disks under the same dbPath , this is the option:
Add the option --directoryperdb in the mongod config file or at startup.
db.createDatabase("newDatabase")
You will see inside the dbPath folder for the new database like:
\dbPath\newDatabase
Stop the mongodb process.
Copy the content from \dbPath\neWDatabase to your SSD let say:
ssd:\newData
make link to the folder with:
mklink /d \newData \dbPath\newDatabase
or follow this tutotial
Start the mongodb process again.
Note:
As suggested by #Wermfried in the comment it is safe to have the option --directoryperdb set initially in the member before to get populated ...

Meteor - unmount existing mongo collection

We are creating Meteor-based Mongo database manager and we need the ability to "unmount" (remove from system) all collections when we switch databases.
Example:
I'm managing database called dbA. We have all collections for that database created using Mongo.Collection() on server and on client side.
I want to switch database to dbB. I need to unmount all Collections of dbA and mount those of dbB. Reason: dbB could have a collection of the same name as dbA (and usually does)
Is there a way to do this?
Thanks!
You may be able to accomplish this by publishing the necessary data from the new database.
Here's a discussion from a similar question on the Meteor Forums (note the proposed solution at the end):
https://forums.meteor.com/t/switch-database-while-meteor-is-running/4361/5
hi i think you can do with
db.copyDatabase()
run the shell command in the backend from meteor server and execute the copy database command. and after the database is copied you can remove the previous collection.
more detail about copyDatabase() is here
https://docs.mongodb.org/manual/reference/method/db.copyDatabase/

Where can I find MongoDB documents created inside Meteor?

New to Meteor and MongoDB here. I have mongoDB running as a service in my server, and from what I understand, Meteor installs it's own mongoDB in the .meteor directory by default, unless you specify otherwise. I know native MongoDB stores its data in data/db folder, but where are the documents located for MongoDB as part of Meteor?
I have found that the mongoDB binary is found (for me) at
~/.meteor/packages/meteor-tool/.1.0.35.ftql1v++os.linux.x86_64+web.browser+web.cordova/meteor-tool-os.linux.x86_64/dev_bundle/mongodb/bin/mongod
But scooping around that area didn't lead me to any documents, nor could I find any mongodb.conf, collection.0, collection.ns files. And there's no directory like .meteor/local/db as some answers suggested.
My question is similar to this one, however, I'm looking for the location on disk of the database documents, rather than the location of the address to access the database.
Question
Where are the documents located for MongoDB as part of Meteor?
They are saved in your project directory at .meteor/local/db.

Where does MongoDB store its documents?

I have inserted and fetched data using MongoDB, in PHP. Is there an actual copy of this data in a document somewhere?
By default Mongo stores its data in the directory /data/db.
You can specify a different directory using the --dbpath option.
If you’re running Mongo on Windows then the directory will be C:\data\db, where C is the drive letter of the working directory in which Mongo was started. This is quite confusing, so on Windows I’d recommend that you always specify a data directory using --dbpath.
MongoDB stores it's data in the data directory specified by --dbpath. It uses a database format so it's not actual documents, but there are multiple documents in each file and you cannot easily extract the data from this format yourself.
To read and/or update a document you need to use a MongoDB client, in the same way that you send SQL queries to MySQL through a MySQL client. You probably want to do it programmatically by using one of the client libraries for your programming language, but there is also a command-line client if you need to do manual updates.

can I use MongoDb in server-less mode?

I'm considering using MongoDb for a backing store for a WPF app that I'm building. Mostly just to get some exposure to NoSQL. Ideally I'd like to make a mongodb database, put it in my application's root folder (or ./data) and connect to it with LINQ -- without having mongo.exe running. I did something similar recently with SQLite and found it to be a great change from XML for data storage.
Is this possible with MongoDb? All the samples that I've seen require mongod.exe to be running when you connect to the database. And the data is always stored in c:\data\db.
Answer, yes. Need to use the --dbpath switch and version 1.5.2 (for "upsert").