客观的
为两列创建唯一性
我尝试了什么
这是我的架构,
var mongoose = require('mongoose');
// location table Schema
var locationSchema = new mongoose.Schema({
locationId: { type: String, required: true },
stockingLocationId: { type: String, required: true},
parentStockingLocationId: { type: String },
stockingLocationDescription: { type: String },
created: { type: Date, default: Date.now },
lastModified: { type: Date, default: Date.now },
isActive: { type: Boolean , default : true },
isDeleted: { type: Boolean , default : false }
});
两列是locationId
and stockingLocationId
.
I tried locationSchema.index({locationId:1, stockingLocationId:1}, { unique: true });
但不起作用,
有什么帮助吗?
在如下所示的字段周围添加单引号后,它对我有用
mySchema.index({'field1': 1, 'field2': 1}, {unique: true});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)