I m building an application in which I use to manage projects. A projects looks like the following :
{
"_id": ObjectId("..."),
"title": "MySuperProject",
"files": [
{
"title":"My skiing day !",
"right":[{
"role":"USER",
"access":["read"]
}]
},
{
"title":"My little dog, so cute !",
"right":[{
"role":"OTHER",
"access":["read"]
}]
}
]
}
We can see two different roles here : USER and OTHER.
When I get the above project with the USER role, I need to have the following representation, without the OTHER file :
{
"_id": ObjectId("..."),
"title": "MySuperProject",
"files": [
{
"title":"My skiing day !",
"right":{
"role":"USER",
"access":["read"]
}
}]
}
Does it exist a way to reduce a list inside of a document based on query or should I make it manually on the result ?
I m working on nodejs and mongoose.
Thanks for your help
EDIT : In fact the right key was an ARRAY