Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does MongoDB store its documents?

Tags:

mongodb

I have inserted and fetched data using MongoDB, in PHP. Is there an actual copy of this data in a document somewhere?

like image 881
Oliver Bayes-Shelton Avatar asked Jun 22 '11 08:06

Oliver Bayes-Shelton


People also ask

How does MongoDB store documents?

Documents are stored on disk using block compression to reduce storage usage. Documents are automatically uncompressed in memory when retrieved by the MongoDB server. Each collection & index is stored in a separate file within the storage.

Where are MongoDB documents stored?

MongoDB requires a data folder to store its files. The default location for the MongoDB data directory is c:\data\db.

Is MongoDB stored in memory?

MongoDB is not an in-memory database. Although it can be configured to run that way. But it makes liberal use of cache, meaning data records kept memory for fast retrieval, as opposed to on disk.

How does MongoDB store files in database?

In MongoDB, use GridFS for storing files larger than 16 MB. In some situations, storing large files may be more efficient in a MongoDB database than on a system-level filesystem. If your filesystem limits the number of files in a directory, you can use GridFS to store as many files as needed.


2 Answers

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.

like image 89
Daniel Cassidy Avatar answered Sep 24 '22 16:09

Daniel Cassidy


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.

like image 37
Emil Vikström Avatar answered Sep 26 '22 16:09

Emil Vikström