Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is better for Mongo: empty field or no field at all?

Tags:

mongodb

In MongoDb - in case i have fields that are not always contain values - which is better practice: keep same fields in all records even if sometimes those fields are empty or not create those field at all?

10x!

like image 898
Alon1980 Avatar asked Jul 02 '13 06:07

Alon1980


1 Answers

The fields will occupy disk space for the key, even if there is no value, so better do not include them; unless you need to find what documents does not contain such field / contain empty field

MongoDB is schemaless and each document in the collection can have different fields, as long as that makes sense for your application.

like image 103
Maxim Krizhanovsky Avatar answered Oct 01 '22 04:10

Maxim Krizhanovsky