0

I have a dictionary of data that looks for example like this:

dict = [{'name': 'test', 'domain': 'www.example.com', 'rawdata':'dbe318e7'},
{'name': 'test2', 'domain': 'www.example.com', 'rawdata':'dbe318e8'},
{'name': 'test3', 'domain': 'www.example.com', 'rawdata':'dbe318e8'}]

I want to do an upsert into mongodb using pymongo where 'rawdata' should be unique and I have it working with this:

for x in dict:
            myColl.update({'rawdata': x['rawdata']}, x, True)

But is this the best way to do it or is there a simpler upsert without looping on the dictionary?

7wonders
  • 1,639
  • 1
  • 17
  • 34
  • 1
    A list comprehension is for filtering a sequence of data but not for calling arbitrary code replacing a standard for loop. Misuse of a Python feature! –  Aug 26 '12 at 15:47
  • Updated my question esaelPsnoroMoN to use a proper loop. – 7wonders Aug 26 '12 at 15:58

1 Answers1

0

There is no other way since you need distinct search criteria for each item of the dict. So the answer is no - which is not different from the behavior of a RDBMS.