6

我想用 mongoose-paginate 和 NodeJS对我的Group-Model进行排序。namedeparture_country

我的组架构

  var GroupSchema = new Schema({
        name: String,
        flight_date: Date,
        ....
        departure_country: {type: Schema.ObjectId, ref: 'Country'},
        ....
  });

国家模式

 var CountrySchema = new Schema({
     name: String,
     code: String,
 });

使用sortBymongoose-paginate 的 -option 按国家/地区排序_ids,我不知道如何告诉它按name.

4

1 回答 1

0

将国家代码设为 Country-Schema 的 _id 怎么样?

然后departure_country: {type: String, ref: 'Country'}

这实际上可能是一个更好的设计。Country-Schemas _id 会很小,国家代码不应该有冲突。此外,GroupSchema您将使用更少的空间来存储“外键” departure_country

那么您就可以进行排序,departure_country并且排序也有可能对国家名称有效。

于 2015-10-19T18:22:21.323 回答