简体   繁体   中英

atomic method in mongoDB using node: find object, create if nonexistant

im having issues finding an atomic method for finding a single object in MongoDB and creating it with some preset values if it doesn't exist yet. I found a thread ( MongoDB atomic "findOrCreate": findOne, insert if nonexistent, but do not update ) but the method findAndModify is deprecated and it seems to me that findOneAndUpdate always updates the object, therefore resetting all my data when an object is found, rather than just returning the found one without changing it.

Thanks in advance, i've searched a lot but didn't find anything that helped me.

查看upsert选项,通常会在找不到文档的情况下创建文档

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM