Behavior of lists of embedded objects seems to be broken #83

sean-lynch opened this Issue Feb 29, 2012 · 2 comments

3 participants


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:


  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.



required_fields does not work with field in list yet. You can however add a "default_values" but as the whole list:

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

    default_values = {'list': [{'name': 'foo', 'age': 42}]}
@namlook namlook closed this May 6, 2012

So, let me get this right, I can't just add only the fields that I need to set the default values but I have to had the whole sub document? I did this but it seems like it creates the new document with default value and than insert the actual document I am trying to save.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment