Mongoose时间戳模式选项是否已索引?

Mongoose时间戳模式选项是否已索引?,mongoose,mongoose-schema,Mongoose,Mongoose Schema,Mongoose版本>=4.0有一个时间戳选项,当时间戳设置为true时,它会为模式创建一个updatedAt和createdAt字段 updatedAt和createdAt字段是否已编制索引?不,它们没有编制索引,您必须自己编制索引,就像其他字段一样 animalSchema.index({"createdAt": 1}); animalSchema.index({"updatedAt": 1}); 读者注意:1表示升序,而不是true。而-1对于那些不经常建立站点级mondodb索引(从

Mongoose版本>=4.0有一个时间戳选项,当
时间戳
设置为
true
时,它会为模式创建一个
updatedAt
createdAt
字段


updatedAt
createdAt
字段是否已编制索引?

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

animalSchema.index({"createdAt": 1});
animalSchema.index({"updatedAt": 1});

读者注意:
1
表示升序,而不是
true
。而
-1
对于那些不经常建立站点级mondodb索引(从今天起)的人来说,意味着下降。@steampowered,如果排序顺序索引不是复合的,应该不重要。@Andy说得对。我想我也在搜索关于简单排序的文档,这显然很重要。对于索引和排序操作,索引键的排序顺序(即升序或降序)并不重要,因为MongoDB可以在任意方向遍历索引。