Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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 (108k 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:

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
2 answers
0 votes
1 answer
asked Jan 5, 2020 in Web Technology by ashely (50.2k points)

Browse Categories

...