Retain corresponding dict order of Model

6 views
Skip to first unread message

Joscha Götzer

unread,
Sep 27, 2016, 7:20:53 PM9/27/16
to Mogo Python Object Wrapper
Hi, first off great job on this wrapper!

I am trying to use it in my application, but I keep stumbling upon the innate "feature" of MongoDB that search() and find() functions will not evaluate two documents to be the same if their fields are permuted, i.e. not in the same order (see here). Is there a way to make Mogo-Models consistent in the way that their fields are sorted lexicographically or at least always the same way (with OrderedDict or bson.son.SON)? 

class A(Model):
   x
= Field(str, required=True)
   y
= Field(str, required=True)

a
= A(x='abc', y='def')
a
.save()

A
.search_or_create(x='abc', y='def')
# This will sometimes create a new entry in the database, sometimes not (probably because of the random ordering of the resulting dict).

Am I doing something wrong here?
Reply all
Reply to author
Forward
0 new messages