I have this document in the mongo engine:
class Mydoc(db.Document): x = db.DictField() item_number = IntField()
And I have this data in the document
{ "_id" : ObjectId("55e360cce725070909af4953"), "x" : { "mongo" : [ { "list" : "lista" }, { "list" : "listb" } ], "hello" : "world" }, "item_number" : 1 }
Well, if I want to click on a mongo list using mongoengine, I do this:
Mydoc.objects(item_number=1).update_one(push__x__mongo={"list" : "listc"})
This works very well if the database query again I get this
{ "_id" : ObjectId("55e360cce725070909af4953"), "x" : { "mongo" : [ { "list" : "lista" }, { "list" : "listb" }, { "list" : "listc" } ], "hello" : "world" }, "item_number" : 1 }
But when I try to pull from the same list using pull in mongo engine:
Mydoc.objects(item_number=1).update_one(pull__x__mongo={'list': 'lista'})
I get this error:
mongoengine.errors.OperationError: update failed ($ pull cannot be applied to value without array)
comparison of offers:
Mydoc.objects(item_number=1).update_one(push__x__mongo={"list" : "listc"}) # Works Mydoc.objects(item_number=1).update_one(pull__x__mongo={"list" : "listc"}) # Error
How can I extract from this list?
I appreciate any help