I want to write a query to update all documents based on a condition but skip the very first one. So far I’ve come with the following query:
collection.find( { field1: "abc" }).sort( { date: -1 } ).skip( 1 ).update( [ { $set: { old: true } } ] )
I’m expecting this to
- find the documents based on the condition
- sort them based on
date
- skip the first one
- update the rest and set the
old
filed to true
However, when I run this it updates all the documents matching the “find” condition and does not skip the first one.
What am I doing wrong?
I’d appreciate any help with any other approach that has the same outcome as I’m looking for.