mongoosepaginate由参考文件sorting

我想用“mongoosepaginate”和“NodeJS”以“ departure_countryname对我的Group Model进行sorting。

我的组架构

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

国家图式

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

用这个国家的_ids来selectmongoose般的分类,我不知道如何用name来分类。

如何使国家编码国家模式的_id?

那么departure_country: {type: String, ref: 'Country'}

这实际上可能是一个更好的devise。 Country-Schema sid很小,国家代码不应该有冲突。 另外在GroupSchema您将使用较less的空间来存储“外键” departure_country

那么你可以通过departure_country进行sorting,这种sorting对于国名也是有效的。