Determines whether a list nested in mongodb already contains the value.
If not, write it.
def is_a_new_thing(an_id):
doc = DB.collection.get('stuff')
the_ids = doc['ids']
setbefore = set(the_ids)
setafter = set(the_ids).add(an_id)
# adding an existing value to a set will not change the set
if setafter.difference(setbefore):
doc.update({'ids': list(the_ids.add(an_id))})
DB.collection.save('stuff', doc)
return True
else:
return False