mongodb useCreateIndex code example

Example 1: DeprecationWarning: current Server Discovery and Monitoring engine is deprecated,

mongoose.connect("paste db link", {useUnifiedTopology: true, useNewUrlParser: true, useCreateIndex: true });

Example 2: how create an index mongodb

db.collection.createIndex({age:1}) //single field asc index on age field
db.collection.createIndex({firstName:1,lastName:-1})//compound index on firstName asc and lastName desc
db.collection.createIndex({locations:1}) //given locations is an array then a multikey index will be created