PaolaJ.
PaolaJ.

Reputation: 11572

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

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? (In sqlalchemy after session flush() I can get id of orm updated/inserted)

Upvotes: 1

Views: 97

Answers (1)

heinob
heinob

Reputation: 19474

You have to use findAndModify to get the modified records. Do not forget upsert:true.

Upvotes: 1

Related Questions