-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Docs
Hello,
I'm not sure if it's the right place to open a issue about the documentation.
For the NodeJs driver documentation in the section:
CRUD Operations > Read Operations > Specify Which Fields To Return
To control which fields appear in the documents return by the read operations, we need to use projection:
const projection =
{ name: 1 }
; |
const cursor = collection.find().project(projection); |
However this syntax doesn't work when using findOne() function.
Based on this Stack Overflow post
If we want to combine findOne() with .project() we need to use the following syntax:
const projection =
{ name: 1 }
; |
const cursor = collection.findOne({email}, projection: {email: 1}) |
I would like to know if it's possible to mention in the documentation that:
find() return a cursor, while the findOne() return the direct result, maybe an ordinary document object, which obviously don't have a .project() attribute.
It will hopefully save time to the next developer