0

I am executing the following code inside a post request:

try{
  const _id = await db.collection('UserInformation').insertOne(userObj);
  await db.collection('LoggedInUser').updateOne({ userId: _id }, { '$set': { 
  'isLoggedIn': true } }, { upsert: true });  
}
catch(e){
  console.log(e);
}

and I am getting the circular dependency error.

When I comment out the following line, everything works fine.

await db.collection('LoggedInUser').updateOne({ userId: _id }, { '$set': { 
  'isLoggedIn': true } }, { upsert: true });

Kindly let me know what may be the issue here and how to rectify it.

1 Answer 1

2

The function insertOne() doesn't return an _id, it returns a InsertOneWriteOpResult. This has a connection field which will likely have circular references.

Use insertedId from the result object instead of the whole object itself.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.