1

Are there any examples of instantiating a Mongoengine Document with an attribute being a ReferenceField from kwargs ?

I am looking for the same test case as "test_kwargs_simple" @ https://github.com/MongoEngine/mongoengine/blob/master/tests/document/instance.py#L2834

But replacing the EmbeddedDocument field by a ReferenceField.

eton_ceb
  • 769
  • 8
  • 14

1 Answers1

1

Yes, just pass some Document like the EmbeddedDocument was in the test:

class Referenced(Document):
    name = StringField()

class Doc(Document):
    doc_name = StringField()
    doc = ReferenceField(Referenced)

classic_doc = Doc(doc_name="my doc", doc=Referenced(name="referenced doc"))
mattjegan
  • 2,724
  • 1
  • 26
  • 37