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

156
Visualizações
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
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