Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (50.2k points)

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?

1 Answer

0 votes
by (107k points)
edited by

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});

Related questions

0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
asked Oct 18, 2019 in Web Technology by Sammy (47.6k points)
0 votes
1 answer
asked Jan 5, 2020 in Web Technology by ashely (50.2k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...