ram*_*lli 2 mongoose mongodb node.js
客观的
为两列创建唯一性
我试过的
这是我的架构,
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 }
});
Run Code Online (Sandbox Code Playgroud)
两列是locationId和stockingLocationId。
我试过 locationSchema.index({locationId:1, stockingLocationId:1}, { unique: true });
但不起作用,
请问有什么帮助吗?
我知道这有点晚了,但沿着这些路线的东西..
mySchema.index({field1: 1, field2: 1}, {unique: true});
Run Code Online (Sandbox Code Playgroud)
在指定的位置
在像下面这样的字段周围添加单引号后,它对我有用
mySchema.index({'field1': 1, 'field2': 1}, {unique: true});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6908 次 |
| 最近记录: |