0 votes
1 view
in Web Technology by (28.9k 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 (63.8k points)

The solution for your query is that you just have to call the index method on your Schema object to do that as shown here. Just refer to the following syntax:

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.8k points)
0 votes
2 answers
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...