Sorting by multilingualism by reference document

I would like to sort my Group model name departure_country using mongoose-paginate and NodeJS.

My Group Scheme :

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

Country Scheme :

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

Using the sortBy option of varieties of the multilingual web by country _ids , and I don’t know how to tell it to sort by name .

+5
source share
1 answer

how to make country code _id country schema?

then departure_country: {type: String, ref: 'Country'}

It may be a better design. Country-Schema _id will be small, and country codes should not have collisions. Also in GroupSchema you should use less storage space for the departure_country "foreign key".

then you can sort by departure_country , and there is a chance that the sorting will also be valid for the country name.

0
source

Source: https://habr.com/ru/post/1233442/


All Articles