node.jsmongodbrealmmongodb-realm

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?


Solution

  • In case anyone else comes across this, it turns out that the documentation is inaccurate and does not reflect the current state of the SDK.

    For reference, see this GitHub Issue where it was confirmed by a Realm dev: https://github.com/realm/realm-js/issues/3275