Is the documentation on `find projection` misdescribed?

The example function given in the documentation is db.collection.find(query, projection, options), but it’s actually db.collection.find(query, options), with projection being an option in options, which Is this an error?

The document address is:

What versions of the server / shell are you using? I don’t normally use a project on a find and just jump straight into an aggregation but this is what I did:


And then:

db.getCollection("Cinemas").find({}, {'Name':'$CinemaName'})


I was also able to do this:

db.getCollection("Cinemas").find({}, {'Name':'$CinemaName'}, {allowDiskUse:true})

I am writing the programme on the nodejs platform and the dependency is mongodb@5.8.1.

I am looking at the prototype of the find function in my IDE and it is:

find(): FindCursor<WithId<TSchema>>;
find(filter: Filter<TSchema>, options?: FindOptions): FindCursor<WithId<TSchema>>;
find<T extends Document>(filter: Filter<TSchema>, options?: FindOptions): FindCursor<T>;

In that case the difference if between the shell method and the node.js API interface.

As you say, the node.js find API passes a projection as an option but the shell call does not, the documentation you linked above was for the shell interface (see yellow warning on the link you sent).

The node.js find API here documents the node.js surface:

1 Like

I’m very sorry I didn’t notice this detail and I hope you can understand.

No worries, I’ve done worse, and probably will do again!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.