【问题标题】:Is the Mongoose timestamps schema option indexed?Mongoose 时间戳模式选项是否已编入索引?
【发布时间】:2016-12-22 03:41:45
【问题描述】:

Mongoose 版本 >= 4.0 有一个时间戳选项,当 timestamps 设置为 true 时,它会为架构创建 updatedAtcreatedAt 字段。

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

updatedAtcreatedAt 字段是否已编入索引?

【问题讨论】:

    标签: mongoose mongoose-schema


    【解决方案1】:

    不,它们没有被索引,你必须自己做索引,就像任何其他字段一样。

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

    【讨论】:

    • 读者注意:1 表示升序,而不是true。而-1 表示降序,对于那些不经常创建站点级mondodb 索引的人(not clearly documented 截至今天)。
    • @steampowered 如果它不是复合的,那么它的排序顺序索引应该无关紧要。
    • @Andy 好点。我想我也在搜索关于简单排序的文档,这显然很重要。
    • 对于 single-field 索引和排序操作,索引键的排序顺序(即升序或降序)并不重要,因为 MongoDB 可以在任一方向遍历索引。
    猜你喜欢
    • 2013-08-14
    • 2019-01-11
    • 2018-10-07
    • 2012-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多