How to prepend an element to a list

39 views
Skip to first unread message

Tamer Abdulradi

unread,
Nov 30, 2011, 8:00:08 AM11/30/11
to MongoEngine Users
Mongoengine can push elements to Lists by appending them

BlogPost.objects(id=post.id).update_one(push__tags='nosql')
I want to prepend instead of appending, is there a way ?

Another alternate question to the same problem ..
I can query in a list by position like this

BlogPost.objects(tags__0='nosql')
Is there a way to specify the last element in the list, like -1 index
in python lists ?

BlogPost.objects(tags__-1='nosql') # ?.. I wish !
Answers to any of two question will solve my problem.
and this is a link to this question on Stackoverflow
http://stackoverflow.com/questions/8326208/how-to-prepend-an-element-to-a-list-in-mongoengine
Thanks in advance.

Dan Crosta

unread,
Nov 30, 2011, 8:25:44 AM11/30/11
to mongoeng...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages