Created
July 24, 2012 02:37
-
-
Save neilkod/3167664 to your computer and use it in GitHub Desktop.
upsert and preserve existing values?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for itm in itms: | |
data = itm | |
rec=coll.find({'text':data}) | |
if rec.count() == 0: | |
print "new item: {0}".format(itm.strip()) | |
coll.insert({'text':data,'count':0,'last_posted': OLD_DATE}) | |
can the coll.find/coll.insert be rewritten to use upsert (coll.update) **and preserve any existing values of count(integer) and last_posted(date)**? | |
each document in the collection will be text, count, last_posted . | |
text: some arbitrary text | |
count: an incremented count | |
last_posted: a date, initialized to an date in 1900. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment