我正在尝试在mongo DB
中插入许多内容。所以我的模式是这个
const BlogPost = new Schema({
id: { type: Number, unique: true },
empid: String,
date: Date
});
我有unique ID
,所以当我尝试保存某些error occured it save some collections
时,如果某些roll back
到来,我想error
保存所有收藏。
这是我的代码 https://codesandbox.io/s/dreamy-bell-9u0bz
const data = [
{
empid: "test123",
id: 4,
date: "19-Jul-2019"
},
{
empid: "test13",
id: 4,
date: "18-Jul-2019"
},
{
empid: "test13",
id: 6,
date: "11-Jul-2019"
}
];
当我尝试保存以上数据it save one collection and then gives error duplicate key
时。我想回滚save集合,因此如果发生错误,将不会保存任何集合。
https://codesandbox.io/s/dreamy-bell-9u0bz