为什么 Mongo 给我 E11000 错误,即使我没有将任何字段设置为唯一?
Why is Mongo giving me the E11000 error even though I don't have any field set to unique?
将第二个文档保存到 MongoDB atlas 时出现此错误:
error:MongoError: E11000 duplicate key error collection: test.orders index: orderId_1 dup key: { orderId: null }
但是,在文档架构中,我没有将任何字段设置为唯一:
const orderSchema = new Schema({
paymentId: {
type: Number
},
paymentStatus: {
type: String
},
paymentToken: {
type: String
},
orderDetails: {
type: Object
},
}, {
timestamps: true
});
错误是什么意思?
我是这样保存的:
const newOrder = new Order({
paymentId,
paymentStatus,
orderDetails,
paymentToken
});
newOrder.save()
.then(() => console.log("order saved!"))
.catch(err => console.log("error:" + err));
错误消息引用了我在您的模型中没有看到的 OrderId_1。我会检查指南针或地图集以确保您没有设置“唯一”索引。
将第二个文档保存到 MongoDB atlas 时出现此错误:
error:MongoError: E11000 duplicate key error collection: test.orders index: orderId_1 dup key: { orderId: null }
但是,在文档架构中,我没有将任何字段设置为唯一:
const orderSchema = new Schema({
paymentId: {
type: Number
},
paymentStatus: {
type: String
},
paymentToken: {
type: String
},
orderDetails: {
type: Object
},
}, {
timestamps: true
});
错误是什么意思? 我是这样保存的:
const newOrder = new Order({
paymentId,
paymentStatus,
orderDetails,
paymentToken
});
newOrder.save()
.then(() => console.log("order saved!"))
.catch(err => console.log("error:" + err));
错误消息引用了我在您的模型中没有看到的 OrderId_1。我会检查指南针或地图集以确保您没有设置“唯一”索引。