Hello I have the first schema for the properties
:
const property = mongoose.Schema({
city: { type: String, default: null },
tags: [
{
_id: { type: mongoose.Schema.Types.ObjectId, ref: "Tag", default: null },
count: { type: Number, default: null },
},
],
});
and the second one for tags
:
const tag = mongoose.Schema({
name: { type: String, unique: true, default: null },
createdAt: { type: Date, default: Date.now },
});
I prepared a playground for testing : Mongo playground
input from the frontend is an array of tag ids example: [1 , 2]
// the array is dynamic.
example of the sorted result:
[
{
"_id": 1,
"city": "Paris", // on top because the tags count is higher
"tags": [
{
"_id": 1, // seen
"count": 43
},
{
"_id": 2, // liked
"count": 32
}
]
},
{
"_id": 2,
"city": "leon",
"tags": [
{
"_id": 1, // seen
"count": 17
}
]
}
]
PLEASE CONSIDER: the tag ids that I need to sort by are in the request coming from the frontend.
I want to sort by total of tag count in properties, so I can get a list of properties with the highest matched tags count on top.
thank you.