namlook/mongokit — Issue #83: Behavior of lists of embedded objects seems to be broken
Author: sean-lynch
Created: 2012-02-29 18:29:59+00:00
State: open

Lists of objects inside a structure seem to be a special case that is not behaving consistently with the rest of the definition. I'm still new to monogkit so I may be doing things incorrectly though so feel free to point me in the right direction.

I've checked in a few test cases to illustrate my points here: https://github.com/sean-lynch/mongokit/blob/master/listembed-test.py

Example:

class ListEmbed(Document):
use_dot_notation = True
structure = {
'list': [
{
'name': basestring,
'age': int
}
]
}

1. You can't specify default values for the embedded object of the list. For example, I'd like to specify that the default value for 'name' is 'New User'. My expectation is that, every embedded object inside the list has this default applied to it if no name value is set. #49 was an attempt to fix this, but it simply sets the default value of the entire list, not of the objects inside the list.

2. fields in the embedded object are treated as required even when not specified in the `required_fields` attribute. With the above definition of a class, I should be able to save a new document with the structure {'list': [{'name': 'Bob'}]} but instead, it complains about age missing.

I've also looked at using DBRefs to accomplish the same thing. I've avoided it so far because I don't want to store the embedded objects separately and pay the performance penalty of rebuilding the list when I query them.