I need to filter results from a single collection, given a collection of characters, some characters do not have userId but others do ( this is because the backend consumes most of the characters from an api and when inserting all the characters in the Characters collection they do not have userId , and the characters that do have a userId is because the user created it from the frontend ) What I want to do is to filter the results so that a user only sees his characters and those of the api (those that do not have a userId), I do not want a user to see the characters of other users, the characters also have professions, I should also filter by professions, an example would be : search by character name, character profession ( this should return all characters that have a certain name and a certain profession, except characters of other users, this is determined by the userId of the user).
This is an example of a character without a userId
{
"_id" : ObjectId("62d836fd459afd6d0fdd7d1c"),
"name" : "Robert",
"api" : true,
"height" : 157,
"weight" : 69,
"profession" : [
{
"_id" : ObjectId("62d836c736bd5ad391b4f7c6"),
"name" : "carpenter",
"api" : true
},
{
"_id" : ObjectId("62d836c736bd5ad391b4f7be"),
"name" : "professor",
"api" : true
}
],
}
This is and example of a character created by a user in the frontend, this have a userId
{
"_id" : ObjectId("62d836fd459afd6d0fdd7d1d"),
"name" : "Martin",
"height" : 177,
"weight" : 79,
"profession" : [
{
"_id" : ObjectId("62d836c736bd5ad391b4f7c6"),
"name" : "carpenter",
"api" : true
},
{
"_id" : ObjectId("62d836c736bd5ad391b4f7be"),
"name" : "barber",
"api" : true
}
],
"userId" : "62d836c636bd5ad391b4f7b9"
}