Mongoose时间戳架构选项是否已编入索引?

ste*_*red 6 mongoose mongoose-schema

Mongoose版本> = 4.0有一个timestamps选项,当设置为时,它为模式创建一个updatedAtcreatedAt字段.timestampstrue

http://mongoosejs.com/docs/guide.html#timestamps

updatedAtcreatedAt字段索引?

enR*_*ser 12

不,它们没有编入索引,您必须自己编制索引,就像任何其他字段一样.

animalSchema.index({"createdAt": 1});
animalSchema.index({"updatedAt": 1});
Run Code Online (Sandbox Code Playgroud)

  • 读者注意:“ 1”表示升序,而不是“ true”。对于那些不经常做站点级mondodb索引的人(从今天起[[http://mongoosejs.com/docs/guide.html#indexes]),"-1“表示下降。 (2认同)
  • @steampowered,如果它不是复合的,则排序顺序索引具有什么都没关系。 (2认同)