I’m using this code to insert (or update if already existing) a new user to the databse:
emailAddress = self.request.params.get('emailaddress')
googleRefreshToken = self.request.params.get('googlerefreshtoken')
# upsert new user
postData = {"emailAddress" : emailAddress,
"googleRefreshToken" : googleRefreshToken}
newPost = self.request.db.users.update( { 'emailAddress' : emailAddress }, postData, True );
return json.dumps( newPost, default=json_util.default)
I’m assuming that update() should return the objects _id or even the object itself…but it always returns null even though the upsert works correctly. Why is it returning null and how can I get it to return the _id or object itself?
As described in the docs, if you include
safe=Truein your parameters toupdate, the response tolastErroris returned, otherwise it returnsNone. If you want the_idof the document updated, you’ll either have to query for it separately or usefind_and_modifyinstead ofupdate.