1

Suppose I want to run query like this

.find(Filters.exists("a", false))
            .sort(Sorts.orderBy(Sorts.descending("b"),Sorts.ascending("c")))

But with findOneAndUpdate operation.

.findOneAndUpate(bson???, Updates.combine(Updates.set("b", 1), Updates.set("c", 2)), callback)

How do I create correct bson parameter, combining both filter and sort?

1 Answer 1

1

You can't combine filter with sort.

FindOneAndUpdate takes three parameters. Pass the first parameter as filter and third parameter is FindOneAndUpdateOptions which takes the sort.

Something like

findOneAndUpdate(filter,update,
                         new FindOneAndUpdateOptions().sort(sort));
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.