0

I'm creating a video sharing site as a test project, and in my mongoose schema, each video has a String array field 'tags', for example, it might look like this:

{
  title: "Test video",
  tags: ["video", "test", "1080p"]
}

and, in order to give suggestions of similar items, I'd like to query my videos table and sort by the ammount of common items between this video's tags array and another's.

For example, a document which also has the tag "1080p" would get a 'score' of 1, but one which has all three tags, "video", "test" and "1080p" would get a score of 3, and then I would sort them by this score descending to get some suggestions of similar documents.

Does anyone know how I can do something like this with Mongoose & Node?

deeBo
  • 836
  • 11
  • 24
  • Check this [Link](https://stackoverflow.com/questions/24410727/mongodb-find-common-element-from-two-arrays-within-a-query). This might help you in this matter – Muhammad Tayyab Shafique Mar 28 '19 at 22:29
  • Hi, thanks, but I'd like to count the amount of common items between the documents' arrays, rather than retrieve them, and then sort by that number – deeBo Mar 28 '19 at 22:36

0 Answers0