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

282
Visualizações
GraphQL MongoDb: InsertOne is not returning back document object

I am using graphQL to retrieve data and mongoDb to create my user. When I run the signup mutation in apollo i get the error: Cannot return null for non-nullable field User.id.

I console.log(result) and it equals:

{ acknowledged: true, insertedId: new ObjectId("6432djjedh3i2o211i12je") }

This is not what I want returned as the result. I want result to equal the whole collection that was inserted, which is this: {_id:6432djjedh3i2o211i12je email:"test@gmail.com" password: "$2a$10$ONkOjWbigkD3fWSo9XdweOzLePZM7CkGa0QgfbVLkyWtS10EU9R5uz8e" name:"name"} (from Mongo Atlas)

My whole signUp Mutation for creating a user is:

Mutation: {
  signUp: async (_, {input }, { db}) => {
    const hashedPassword = bcrypt.hashSync(input.password);
    const newUser = { 
      ...input, 
      password: hashedPassword
    }

    const result =  await db.collection('Users').insertOne(newUser)
    console.log(result);

    //result gets reassigned as user
    const user = result
    
    return { 
      user, 
      token: 'token'
    }
}
  }

update tried console.log(result.ops[0]) instead but didnt work.

about 4 years ago · Santiago Gelvez
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