Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

281
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda