[英]How to know if upsert was successful and if I can get _id of updated/new inserted document
I am using this code to make upsert functiona to mongo server via mongoose 我正在使用此代码通过mongoose将功能upsert插入mongo服务器
update({'name' : 'Jaki'}, {'name' : 'Charley', 'gender' : 'f'}, {upsert: true})
and it works, but how to know if operation was successful and if I can get _id
of updated/new inserted document? 并且可以正常工作,但是如何知道操作是否成功以及是否可以获取已更新/新插入文档的_id
? (In sqlalchemy after session flush() I can get id of orm updated/inserted) (在会话flush()之后的sqlalchemy中,我可以获取更新/插入的orm的ID)
You have to use findAndModify to get the modified records. 您必须使用findAndModify来获取修改后的记录。 Do not forget upsert:true
. 不要忘记upsert:true
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.