Please look at the following lines of code and the results:
import pymongo
d1 = {'p': 0.5, 'theta': 100, 'sigma': 20}
d2 = {'theta': 100, 'sigma': 20, 'p': 0.5}
I get the following results:
d1 == d2 // Returns True
collectn.find({'goods.H': d1}).count() // Returns 33
collectn.find({'goods.H': d2}).count() // Returns 2
where, collectn
is a Mongodb collections object.
Is there a setting or a way to query so that I obtain the same results for the above two queries?
They are essentially using the same dictionary (in
the sense of d1 == d2
being True
). I am trying to do the following:
before inserting a record into the database I check whether there
already exists a record with the exact value combination that is being added.
If so, then I don't want to make a new record. But because of the above
shown behavior it becomes possible to get that the record does not exist even
when it does and a duplicate record is added to the database (of course, with different _id
but all other values are the same, and I would prefer not to have that).
Thank you in advance for your help.