0

I have a model in MongoDB called "order". It has a field called "status" and a field called "last_status". There is a function which has to set a value to field "status".

My question is when I do it like this:

let order = await OrderModel.findOneAndUpdate(
{
  _id: ObjectId(orderId),
},
{
  $set: {status: ORDER_STATUS.CANCELED, 'cancelInfo.lastStatus': status},
},

Does the 'cancelInfo.lastStatus' field gets previous value of status or gets it's new value.

Thanks for any help.

Kamran Hosseini
  • 478
  • 5
  • 25
  • 1
    Possible duplicate of [Update MongoDB field using value of another field](https://stackoverflow.com/questions/3974985/update-mongodb-field-using-value-of-another-field) – ProgrammingLlama Nov 26 '17 at 10:51
  • Is describing setting the value of "lastStatus" to the former value of "status", whilst setting "status" _not_ setting the value of a field using another field's value? If not, where do you expect "status" comes from? If that's not what you're asking then I really don't understand the content of your question. – ProgrammingLlama Nov 26 '17 at 11:12
  • @john I want to set 'status' to 'cancelInfo.lastStatus' which both are "OrderModel" fields. But my problem is that "status" is also changing in the same query and I want to set to 'cancelInfo.lastStatus' the former value of 'status'. – Kamran Hosseini Nov 26 '17 at 15:31

0 Answers0