I want to receive all items first where the sort designation matches. An article is assigned to a category. However, a user can specify several categories (array). So I want to see if an item matches a category from the array and if so, it will be returned with a higher rating.
const artikel = await Artikel.find({
art: req.params.filter,
userId: { $ne: req.body.userId },
})
.sort([req.body.kategorie, 1]) //USER = req.body.kategorie is an Array ['KFZ','Garden']
.limit(10)
.skip(req.body.page * 10);
Articel Schema:
const ArtikelSchema = mongoose.Schema(
....
kategorie: {
type: String,
required: true,
},
)
User Schema:
const UserSchema = mongoose.Schema(
...
kategorie: {
type: [String],
default: [],
},
)