Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for compound indexes #51

Open
BusbyActual opened this issue Mar 28, 2018 · 1 comment
Open

Support for compound indexes #51

BusbyActual opened this issue Mar 28, 2018 · 1 comment

Comments

@BusbyActual
Copy link

The current version appears to support unique keys however not complex unique keys.

Example

const mongoose = require('mongoose');
const beautifyUnique = require('../scripts/mongoose-beautiful-unique-validation');
const Schema = mongoose.Schema;

let modelSchema = new Schema({
  name: { type: String, required: true, max: 100 },
  serial: { type: String, required: true, max: 100 },
  foreignKey: { type: String, required: true, max: 100 },
  created: { type: Date, default: () => new Date() }
});

modelSchema .index({ foreignKey: 1, serial: 1 }, { unique: true });
modelSchema .plugin(beautifyUnique);

module.exports = mongoose.model('model', modelSchema );

Suggested

modelSchema .index({ foreignKey: 1, serial: 1 }, { unique: "'{VALUE}' is already in use" });
@sanwalfarooque
Copy link

@BusbyActual
Any update on this ? Custom message for compound indexes ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants