I'm writing a small web app with the Pyramid framework (which is awesome) and I'm having trouble updating a document. I have no problems querying for a document with the same id- I just can't seem to update it. Here is the code I'm using:
for key, value in request.POST.iteritems():
if value:
to_insert[key] = value
if "_id" in request.POST:
try:
_id = ObjectId(request.matchdict['id'])
except InvalidId:
return Response("Error generating id")
request.db['concerts'].update(
{ '_id': _id },
{ "$set": to_insert },
upsert=False
)
If I do:
request.db['concerts'].find( {'_id' : _id }
I find the document that I wish to update, so it doesn't seem to be an issue of the id not being there. It just doesn't seem to commit anything to the database. The only issue I could see is that I update the entire document- I don't check the fields beforehand. Is this the proper way to go about this? I didn't see much in the documentation about updating an indiscriminate number of fields.