【发布时间】:2016-12-22 03:41:45
【问题描述】:
Mongoose 版本 >= 4.0 有一个时间戳选项,当 timestamps 设置为 true 时,它会为架构创建 updatedAt 和 createdAt 字段。
http://mongoosejs.com/docs/guide.html#timestamps
updatedAt 和 createdAt 字段是否已编入索引?
【问题讨论】:
Mongoose 版本 >= 4.0 有一个时间戳选项,当 timestamps 设置为 true 时,它会为架构创建 updatedAt 和 createdAt 字段。
http://mongoosejs.com/docs/guide.html#timestamps
updatedAt 和 createdAt 字段是否已编入索引?
【问题讨论】:
不,它们没有被索引,你必须自己做索引,就像任何其他字段一样。
animalSchema.index({"createdAt": 1});
animalSchema.index({"updatedAt": 1});
【讨论】:
1 表示升序,而不是true。而-1 表示降序,对于那些不经常创建站点级mondodb 索引的人(not clearly documented 截至今天)。