kurttheviking
kurttheviking

Reputation: 614

Node mongo options parameters vs cursor methods

I've noticed a few instances within the node MongoDB driver where one can perform a cursor operation either through an options parameter or through a chained method, as shown below. Do these perform the same operation or is there some difference (e.g. performance characteristics) between the two?

This example uses sort though the same applies in other cases as well (e.g. limit). First, as an options parameter:

db.collection.find({}, {sort: {_id: 1}})

Now, as a chained cursor method:

db.collection.find({}).sort({_id: 1})

Upvotes: 2

Views: 84

Answers (1)

JohnnyHK
JohnnyHK

Reputation: 311895

Those are just two different ways to perform the exact same operation.

In both cases the result is a Cursor with a doc selector of {} and a sort parameter of {_id: 1}.

Upvotes: 2

Related Questions