Search code examples
pythonmongodbmongoengine

Clear a list in Mongoengine


With this schema:

class XSet(db.Document):
    xs = db.ListField(db.EmbeddedDocument('X'))
#   ...

class X(db.Document):
    pass

Then:

 xset = XSet.objects(id="uniqueid").get()
 xs = xset.xs

How can I delete all the X instances stored in xs? (If possible, I'd very much like to stay within the Mongoengine abstraction.)


Solution

  • I'm not sure about efficiency, but this works:

    for x in xs:
      del x