Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!