using pull_all and push_all with python/mongoengine

I have this object in Mongo:

mystuff = ListField(ReferenceField(Asset, dbref=True))

I have a Python method that is supposed to update the Mongo object, prepending its mystuff Listfield value with a given value. Because Mongoengine doesn't yet have a way to insert an object into a certain point in a list (and has made it a low priority to add this function), I've tried to:

  1. save the contents of the current list to a temporary variable (oldlist)
  2. update the DB entry, emptying the mystuff list using the "pull_all" modifier (which is part of mongoengine)
  3. update the DB entry again, pushing the newly added item to the mystuff list using update(push)
  4. update the DB entry once again, using the "push_all" modifier and the oldlist variable to push the old stuff back onto the mystuff list.

It seems that "pull_all" requires some kind of modifier, but I'll be danged if I can figure out what it wants.

Anybody got any ideas? Of course the ideal situation would be to add an "insert_at" modifier to update(), but that's out of my hands. Life on the edge, etc.


The pull_all takes a list of elements you want to pull out of the list. In you're case I believe this will be oldlist.

However I think you're best bet is probably to retrieve the whole document with get, modify the mystuff field in the client code, and send it back with a save.

As you noted the tools for updating the document in place are limited.

Need Your Help

WPF Edit Mask

wpf wpf-controls

What is the easiest way to specify an edit mask in WPF for a simple Text Box?

How to display an image in Flash datagrid after selecting an image for uploading?

flash actionscript-3 image datagrid upload

After browsing for the images, and selecting them. How can I display a preview of the image in the datagrid? I am able to display the file name, file size, but was unable to display the image. Belo...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.