1.方式一:在定义schema的时候

2.方式二:另一种方法是通过index方法添加
比如给name和age字段添加索引(1表示升序索引,-1表示降序索引)
animalSchema.index({ name: 1, age: -1 });
1.方式一:在定义schema的时候
2.方式二:另一种方法是通过index方法添加
比如给name和age字段添加索引(1表示升序索引,-1表示降序索引)
animalSchema.index({ name: 1, age: -1 });
本文标题:mongoose给字段添加索引的方法
本文链接:https://www.haomeiwen.com/subject/ijflfxtx.html
网友评论