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

155
Views
Search in MongoDB with Graphql (Foreign Key)

Good afternoon.

I have 2 collections in mongoDB with a one-to-many relationship, where one of the collections receives the foreign key of the other.

const Sport = mongoose.model('Sport', new Schema({
_id: {
type: String,
default:() => uuid()
},
name: { type: String, required: true }
}))

const Event = mongoose.model('Event', new Schema({
_id: {
type: String,
default:() => uuid()
},
name: { type: String, required: true },
sport_id: { type: String, required: true }
}))

I want to do searches on these collections with graphql and when searching for Event, show the data from 'sport_id' instead of just showing the String. How do I do? How do I make the rootvalue?

type Sport {
        _id: String
        name: String
    }

type Event {
        _id: String
        name: String
        sport_id: Sport
    }

type Query {
        sport(name: String): [Sport!]
        sportById(_id: String): Sport

        event(name: String, sport_id: String): Event!
        eventById(_id: String): Event
    }
about 4 years ago · Juan Pablo Isaza
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!