Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

124
Visualizações
How i can do this mongodb query?

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"
}
about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda