MongoDB Java API:com.mongodb.DBCollection.Save() 和 com.mongodb.DBCollection.Insert() 之间的区别? [英] MongoDB Java API: Difference between com.mongodb.DBCollection.Save() and com.mongodb.DBCollection.Insert()?

查看:23
本文介绍了MongoDB Java API:com.mongodb.DBCollection.Save() 和 com.mongodb.DBCollection.Insert() 之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来这两个方法都将一个BasicDbObject保存到一个集合实例中.这两个方法有什么区别?com.mongodb.DBCollection.Insert()com.mongodb.DBCollection.Save()

It looks these two methods both save a BasicDbObject to a collection instance.What is the difference between these two methods? com.mongodb.DBCollection.Insert() com.mongodb.DBCollection.Save()

推荐答案

Save 一次只能保存一个对象.如果提供了 _id 并且它已经存在,则新文档将覆盖先前存在的文档.如果它不存在,它会做一个插入.

Save can only save one object at a time. If _id is provided and it already exists, the new document will overwrite the previously existing one. If it doesn't exist, it will do an insert.

Insert 可以接受单个对象或对象的 ArrayList,并对它们进行批量插入".

Insert can take a single object or an ArrayList of objects and do a "bulk insert" of them.

如果您将现有的 _id 赋予插入,则会导致重复的 Id 异常.

If you give an existing _id to an insert it will cause a duplicate Id exception.

这篇关于MongoDB Java API:com.mongodb.DBCollection.Save() 和 com.mongodb.DBCollection.Insert() 之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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