NodeJS SDK $project syntax? (mongo query projections)
See original GitHub issueGoals
(copied from SO post https://stackoverflow.com/questions/63942993/mongodb-realm-nodejs-sdk-project-syntax)
I’m trying to do a simple query where some collection data is returned. I want to filter out the _id
field in the results.
From my understanding (based on the documentation) the syntax to do so should look like this:
myCollection.findOne(
{ name: hostName },
{ $project: { _id: 0 } }
)
However when I do this the filter has not been applied, e.g.:
{
_id: XXXXXXXXXXXXXXXXXXXX,
name: 'the name',
...
}
Can anybody point me in the right direction?
Expected Results
Receiving a filtered query result
Actual Results
The entire query was returned.
Steps to Reproduce
Use the sample code above in your own database. Try to use a projection to filter a query.
Version of Realm and Tooling
- Realm JS SDK Version:
10.0.0-beta.12
- Node or React Native: Node
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Specify Which Fields to Return — Node.js - MongoDB
Use a projection to control which fields appear in the documents returned by read operations. Many requests only require certain fields, so projections...
Read more >MongoDB projection syntax - node.js - Stack Overflow
Another behavior is that when I try to project the name on the mongo shell, the result is only the document _id ....
Read more >CRUD with the MongoDB Node.js SDK - Retool
Get help navigating selectOnes, understanding projections, figuring out the differences between insertMany and bulkWrite, and funky SQL ...
Read more >MongoDB Projection & Projection Operators Explained
MongoDB projection uses the same find syntax, but we also add a set of parameters to the find function. This set of parameters...
Read more >MongoDB findOne Example - DigitalOcean
MongoDB findOne() syntax is: db.collection.findOne(<criteria>, <projection>) criteria - specifies the selection criteria entered. projection ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@johnsaigle If you go to https://docs.mongodb.com/realm/node/mongodb/, you can leave a comment by clicking “No” to “Was this page useful?”. The docs team will then be notified.
Hello @johnsaigle, I completely understand your confusion - it seems the docs & SDK are not currently aligned. I believe it’s
projection
instead of$project
, as: