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


Categories

...