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()?

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

问题描述

看起来这两种方法既节省BasicDbObject到集合instance.What是这两种方法之间的区别?
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()

推荐答案

保存只能保存一个对象在同一时间。如果提供_id,它已经存在,新的文件将覆盖previously现有之一。如果它不存在,它会做一个插入。

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.

插入可以采取单个对象或对象的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天全站免登陆