MongoDB 3.2-在findOneAndUpdate上使用updateOne的用例 [英] MongoDB 3.2 - Use cases for updateOne over findOneAndUpdate

查看:88
本文介绍了MongoDB 3.2-在findOneAndUpdate上使用updateOne的用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天的好奇心之一.

我意识到findOneAndUpdate确保原子操作,所以我假设updateOne不能.

I realize that the findOneAndUpdate ensures an atomic operation, so I'm assuming that updateOne does not.

但是我真的不知道避免原子化会带来的巨大好处,否则会超出必须花费额外的时间进行推理并检查更新是否是原子化的成本.

But I really don't know the big perks of avoiding atomic that could out- weigh the cost of having to spend the extra time reasoning and checking if the updates were atomic or not.

一些见识或用例示例将是很棒的!

Some insight or a use case example would be great!

推荐答案

我意识到findOneAndUpdate确保了原子操作,所以 我假设updateOne不会.

I realize that the findOneAndUpdate ensures an atomic operation, so I'm assuming that updateOne does not.

为什么要假设呢?

findOneAndUpdate返回一个文档,updateOne不返回(如果创建了新文档,它仅返回ID).我认为这是主要区别.因此updateOne的用例是当您不需要文档并希望节省一些时间和带宽时.

findOneAndUpdate returns a document, updateOne doesn't (it just returns the id if it has created a new document). I think that's the main difference. So the use case of updateOne is when you don't need the document and want to save a bit of time and bandwidth.

这篇关于MongoDB 3.2-在findOneAndUpdate上使用updateOne的用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆