I am working with a MongoDB database that consists of 3 collections. Each collection is exemplified below by a document:
tag
_id: ObjectId('61b873ec6d075801f7a97e18')
name: 'TestTag'
category: 'A'
computer
_id: ObjectId('6098c5ab615d9e23543d0f6f')
name: 'TestComputer'
category: 'A'
tags: [
'TestTag'
]
setting
_id: ObjectId('61e56339b528bf009feca149')
name: 'FirstSetting'
category: 'A'
priority: 1
tags: [
ObjectId('61b873ec6d075801f7a97e18')
]
_id: ObjectId('61e56339b528bf009feca150')
name: 'SecondSetting'
category: 'A'
priority: 2
tags: [
ObjectId('61b873ec6d075801f7a97e18')
]
The main concept here is that a tag can be created and used to tag computers and settings, but only within the same category:
For instance, a tag with the category 'A' can only be attached to computers and settings of category 'A'
A computer can have only one active setting at a time. The active setting is determined by the tag they share. If a device shares tags with multiple settings, the one with the highest priority takes precedence.
So, following these guidelines, I aim to include a new activeSetting property to each device, as shown below:
computer
_id: ObjectId('6098c5ab615d9e23543d0f6f')
name: 'TestComputer'
category: 'A'
tags: [
'TestTag'
]
activeSetting: ObjectId('61e56339b528bf009feca149')
My Attempt:
I have attempted to use lookup
to retrieve lists of computers and settings for each tag, but I am unsure what steps to take next.