Where does MongoDB store its documents? - mongodb

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.

Related

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.

server side Mongodb GridFS file copying

Per business requirements I need provide possibility to copy content of some file on GridFS. Of course it can be done over domain-specific layer. But in this case I can see some overhead:
take stream from mongo-server
allocate memory on business-layer
read
place back to mongo-server
Obvious solution is write mongo-side JavaScript that will perform copying in bound of single server.
So my questions:
Where is the description of API to manage GridFS on JavaScript?
Is there any issues if my GridFS is sharded?
Is there any issues if my GridFS is replicated?
Thank you in advance
You never need to copy a GridFS file within a single server, because GridFS files are immutable: you can create, read, or delete them, but not modify them. So there's no reason to make a copy.
Copying from one server to another should be done via a driver; there's no built-in support for copying directly from a MongoDB server to another.
The 'normal' js driver does not support GridFS.
You could do it in Node.js. The documentation is here:
http://mongodb.github.com/node-mongodb-native/markdown-docs/gridfs.html
For replica-sets the documentation can be found here for Node.js:
http://mongodb.github.com/node-mongodb-native/markdown-docs/replicaset.html
For simple one-time copying of some files you can use mongofiles on command line (using a temporary file :( ) :
http://www.mongodb.org/display/DOCS/GridFS+Tools
mongofiles --host HOST get currentfilename
mongofiles --host HOST put -l currentfilename newfilename
rm currentfilename
I however don't know how well mongofiles works with sharding and replicas but I would expect it to work.
gridfs_session = gridfs.GridFS(mongo.session)
out_file = gridfs_session.get(file_id)
new_copy = gridfs_session.put(out_file, content_type=out_file.content_type)

Can MongoDB databases be stored in different directories?

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.

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