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

278
Views
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
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!