Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't pull from embedded document field #131

Open
dblado opened this issue Dec 7, 2019 · 0 comments
Open

can't pull from embedded document field #131

dblado opened this issue Dec 7, 2019 · 0 comments

Comments

@dblado
Copy link
Contributor

dblado commented Dec 7, 2019

django-mongoengine==0.3.3
mongoengine==0.17.0

I have the following models in a Django app:

from django_mongoengine import Document, EmbeddedDocument, fields

class TestEmbModel(EmbeddedDocument):
    list_of_strings = fields.ListField(fields.StringField(), blank=True)

class TestModel(Document):
    some_embedded_doc = fields.EmbeddedDocumentField('TestEmbModel', blank=True)

When using:

a=TestModel()
a.save()

This works:
a.update(add_to_set__some_embedded_doc__list_of_strings='abc')

This does not work:
a.update(pull__some_embedded_doc__list_of_strings='abc')

---------------------------------------------------------------------------
OperationError                            Traceback (most recent call last)
<ipython-input-1-3e6ce99e224a> in <module>()
     14 
     15 a.update(add_to_set__some_embedded_doc__list_of_strings='abc')
---> 16 a.update(pull__some_embedded_doc__list_of_strings='abc')

/Users/dblado/.virtualenvs/vendop/lib/python2.7/site-packages/mongoengine/document.pyc in update(self, **kwargs)
    593 
    594         # Need to add shard key to query, or you get an error
--> 595         return self._qs.filter(**self._object_key).update_one(**kwargs)
    596 
    597     def delete(self, signal_kwargs=None, **write_concern):

/Users/dblado/.virtualenvs/vendop/lib/python2.7/site-packages/mongoengine/queryset/base.pyc in update_one(self, upsert, write_concern, full_result, **update)
    592             write_concern=write_concern,
    593             full_result=full_result,
--> 594             **update)
    595 
    596     def modify(self, upsert=False, full_response=False, remove=False, new=False, **update):

/Users/dblado/.virtualenvs/vendop/lib/python2.7/site-packages/mongoengine/queryset/base.pyc in update(self, upsert, multi, write_concern, full_result, **update)
    541                 message = u'update() method requires MongoDB 1.1.3+'
    542                 raise OperationError(message)
--> 543             raise OperationError(u'Update failed (%s)' % six.text_type(err))
    544 
    545     def upsert_one(self, write_concern=None, **update):

OperationError: Update failed (Cannot apply $pull to a non-array value)

If I change Document, EmbeddedDocument to use mongoengine instead of django_mongoengine it works:

from mongoengine import Document, EmbeddedDocument, fields

I think this is related to MongoEngine/mongoengine#1534

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant