1

My mongoDB documents have the following structure:

{
  _id: 'objectID',
  isFlexible: true, // || false
  date: 'date type string',
  availability: ['thursday.morning', 'thursday.afternoon', 'thursday.evening']
}

I want to be able to select some of the documents by isFlexible: true and change the date to today's date (this is easy) and also change the availability array to become:

availability: ['friday.morning', 'friday.afternoon', 'friday.evening']

I know I can do this this if I first find all documents, modify them inside the nodeJS/expressJS API and save them afterwards but I'm looking for a solution where this can be done in a single call to mongoDB.

Any help is greatly appreciated.

1 Answer 1

1

You can build the new availability: ['friday.morning', 'friday.afternoon', 'friday.evening'] inside the API and send it to be saved inside the DB as is instead of trying to change it inside the query.

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.