I have something I cant find a solution for …
Let me explain in in short:
Step 1. Create a new collection in document A
Step 2. Use this id and create a new collection in document B
Step 3. Update collection from step 1 with the id from step2
In nodejs:
DocumentA.create({something})
.then((result)=>{
DocumentB.create({x : result.id})})
.then((result2) => {
DocumentA.updateOne({_id: ?????}, {$set:{y: result2.id}})
And completely stuck here (at the ????) as I cannot use ‘result’ anymore.
>Solution :
I would encourage switching to using async/await but you can do something like this:
DocumentA.create({something})
.then((result)=>{
return Promise.All([
Promise.resolve(result),
DocumentB.create({x : result.id})
])
.then(([result, result2]) => {
DocumentA.updateOne({_id: result._id, {$set:{y: result2.id}
})
The primary thing is to use return <Promise> to pass to the next .then