有没有办法返回所有重复的键错误?
目前,它仅返回fieldA
作为错误。
我想要错误返回所有唯一字段。
const mongoose = require('mongoose')
const Schema = mongoose.Schema
let schema = new Schema({
fieldA: {
type: String,
required: true,
unique: true
},
fieldB: {
type: String,
required: true,
unique: true
}
})
let model = mongoose.model('collection', schema)
model.create([
{
fieldA: 'foo',
fieldB: 'bar'
},
{
fieldA: 'foo',
fieldB: 'bar'
}
], (err, doc) => {
// It returns only collections.$fieldA_1 dup key: { : "foo" }'
console.log(err)
console.log(doc)
})