Back
I'm trying to find documentation on how to create multi-field indexes in Mongoosejs, but couldn't able to find.
Basically, I have two fields that need to be indexed and unique. Can you provide me the mongoose schema that indexes two fields together?
The answer to your question is that on your Schema object, you have to call the index method. The procedure is as follows:
Are you interested in Full Stack Development? Enroll in Intellipaat's Full Stack Developer Certification to learn from experts.
mySchema.index({field1: 1, field2: 1}, {unique: true});
31k questions
32.8k answers
501 comments
693 users