0

In MongoDB, How do i restrict the data entry bases on 3 fields RegisterUserId ,PageId and IsFavourite. None of them is unique? what should the query be?

Below is my Schema

var FavMasterSchema = new Schema({
    FavUrl:String,
    RegisterUserId :  { type: Schema.Types.ObjectId, ref: 'User',select: false},
    PageId:  { type: Schema.Types.ObjectId},
    IsFavourite: {type: Boolean,default:false}

});
module.exports = mongoose.model('t_FavMaster', FavMasterSchema);
2
  • I didn't get you!!! can explain it properly ?? Commented Feb 16, 2018 at 9:17
  • How do i restrict the data entry bases on 3 fields RegisterUserId ,PageId and IsFavourite. None of them is unique. Commented Feb 19, 2018 at 4:31

1 Answer 1

1

Try this:

var FavMasterSchema = new Schema({
    FavUrl:String,
    RegisterUserId :  { type: Schema.Types.ObjectId, ref: 'User',select: false},
    PageId:  { type: Schema.Types.ObjectId},
    IsFavourite: {type: Boolean,default:false}

});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.