【问题标题】:Mongoose subdocuments sortMongoose 子文档排序
【发布时间】:2013-04-18 10:25:51
【问题描述】:

这其实是两个问题。

使用 MongooseJS

  1. 能否为 Schema 设置默认排序顺序?
  2. 您能否控制子文档的排序方式?

【问题讨论】:

  • 我不确定答案。我可以四处搜索,也许看看代码,但也许如果你解释你想要完成的事情,有人可以提供另一种方法。

标签: javascript node.js express mongoose


【解决方案1】:

看看options available for Schema creation,这似乎不是一个可用的选项:

autoIndex: bool - defaults to true
bufferCommands: bool - defaults to
true capped: bool - defaults to false
collection: string - no default
id: bool - defaults to true
_id: bool - defaults to true
minimize: bool - controls document#toObject behavior when called manually - defaults to true
read: string
safe: bool - defaults to true.
shardKey: bool - defaults
to null strict: bool - defaults to true toJSON - object - no default
toObject - object - no default
versionKey: bool - defaults to "__v"

您也许可以创建一个 plugin 来完成您想做的事情。

【讨论】:

    猜你喜欢
    • 2021-07-19
    • 2016-09-18
    • 2015-12-20
    • 2016-01-08
    • 2016-09-15
    • 2019-10-09
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    相关资源
    最近更新 更多