Field names within a MongoDB Schema

In traditional RDBM systems it was quite common to use two (or three or four) word field names. For example university-name or facebook-id. This of course also works in MongoDB.

However I've noticed that when I'm in a situation whereby I cannot think of an obvious single word field name for something in MongoDB, it's often best to model the data as embedded documents.

For example rather than having:


it's better to go with:


This means that when, later down the line, you decide that you now also want to start storing other information, for example the user's Facebook name, this can be added using:

{"facebook":{"name":"Bob Sanders"}}

which just feels more semantically correct to me than having to add:

{"facebook-name":"Bob Sanders"}

As MongoDB understands document structure, doing this makes it no harder to index or query the data. In fact I've found it makes it easier to query as you can still request a single field using:

{"":1 }

Or you can request all information about a Facebook account using:


Otherwise you would have to request the two fields separately.