Objective
To create uniqueness for two columns
what i tried
Here is my schema,
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 }
});
Two columns are locationId
and stockingLocationId
.
I tried locationSchema.index({locationId:1, stockingLocationId:1}, { unique: true });
but not works,
Any help Please?