Mongodb New Developer Q & A

Some questions about mongodb which I set about trying to find answers to before I started using it for a big project. Hopefully to help you get to know mongodb better to see if it suits your needs.

MongoDB uses BSON documents to store data. What is BSON?

“BSON is a binary-encoded serialization of JSON-like documents. BSON is designed to be lightweight, traversable, and efficient. BSON, like JSON, supports the embedding of objects and arrays within other objects and arrays. See bsonspec.org for the spec and more information in general.”

[http://docs.mongodb.org/meta-driver/latest/legacy/bson/]
[http://blog.mongodb.org/post/114440717/bson]
[http://docs.mongodb.org/manual/reference/glossary/#term-document]


Does mongodb use more space if it is formatted json? rephrased – if you store the json as minified does this speed it up?

I couldn’t find anything on this? I’m just guessing but I think minifying the BSON will provide some performance increases but obviously decreases readability. More on this soon….


I’ve heard MongoDB can lose data. Is this true?

Mongodb uses lazy saving upto 1 minute to save your data. So if your running a single process and it goes down you lose that data. If your running multiple processes then you only lose the data on that process.


Is storing shorter property names worth it in terms of speed and storage saves?

It seems possible to have a source code version and shortened property version dynamically generated and stored in production.

As the cost of each GB storage is fairly low it seems naming doesn’t matter too much, keep your property names short and meaningful. If you want significant performance upgrades these are things you can do after you have a solid data set.


Does storing data keys with every piece of data (document) increase the amount of storage required by much?

It seems this can increase the data store by a considerable amount. I am yet to find solid proof of this but there are packages like mongominify (PHP driver) [https://github.com/marcqualie/mongominify] which help to save space leaving readable code while storing minified data.

Is archiving data easy with mongodb and can be accessed easily? rephrased – is it better to provide smaller JSON files (BSON documents) and archive larger files?


Whats the maximum document size while keeping fast speed of read/write?


Are mongodb JSON queries faster than postgres or mysql?

Yes they are shorter.

SELECT json_data FROM people WHERE json_data->’age’ > 15
vs
db.people.find( { age: { $gt: 10 } } )


How much do MongoDB backups cost?

Backups using MMS. [https://mms.mongodb.com/pricing]
$1.00 / GB (OPLOG PROCESSING) + $0.08 / GB (SNAPSHOT STORAGE) = Monthly Bill

Backup cost calculations:
So say you have 3 GB total data and keep snapshots daily for 7 days then after that weekly for 8 weeks then after that monthly.

yearly price = (3 * $1) + ((7 + 7 + 10) * $0.08) * 12 = $4 + $14.8 * 12 = $18.8 per month * 12 = $225.60 a year.

So around $20 bucks a month for mongodb database backups doesn’t seem to bad.


What drivers to i used with mongodb and node.js?

Basic Node.js MongoDB Driver [http://docs.mongodb.org/ecosystem/drivers/node-js/] manual [http://mongodb.github.io/node-mongodb-native/] git [https://github.com/christkv/node-mongodb-native]
ODM Node.js MongoDB Driver – Mongoose [http://mongoosejs.com/]


Does MongoDB use a lot of RAM?

Short answer: Yes and No.
“MongoDB has no configurable cache. MongoDB uses all free memory on the system automatically by way of memory-mapped files. ”
This is answered in more detail here: [http://docs.mongodb.org/manual/faq/fundamentals/#does-mongodb-require-a-lot-of-ram]


Production tip use 64-bit versions of MongoDB!

32-bit is limited to storage of 2gb of data while 64-bit is virtually unlimited.
read more: [http://docs.mongodb.org/manual/faq/fundamentals/#what-are-the-limitations-of-32-bit-versions-of-mongodb]


For more see the Official MongoDB FAQ. [http://docs.mongodb.org/manual/faq/] and fundamentals FAQ [http://docs.mongodb.org/manual/faq/fundamentals/]