Nested Properties Performance in MongoDB

I’m in the processes of modeling a MongoDB database which will be used to live query people depending on specs like their facial features ( hair color, skin tone ), body features ( size, height ), etc

For organizational purposes, I’m thinking about nesting those properties in groups as described above, e.g.:

{
id: 42424
username: John_Doe
face : {
    hair_color: blonde;
    skin_tone: white;
},
body : {
    weight: 100lbs;
    size: 5'7;
}
}

Performance-wise, would this be a good model if I know that the operator will often search depending on nested categories like face.hair_color and body.size ?
Or is retrieving nested values much slower ?

As long as you have adequate indexing, performance should not be an issue. However, there are limits on indexes which you should be aware of.

As far as Meteor’s livedata (reactivity) is concerned, that will identify changes anywhere in the tree, but will always synchronise at the base level. So in your example, if the hair_color changed from 'blonde' to 'auburn', the complete face subtree would be moved over the wire.

1 Like