Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeprecationWarning raised when using a find options string #308

Open
matburnham opened this issue May 23, 2020 · 0 comments
Open

DeprecationWarning raised when using a find options string #308

matburnham opened this issue May 23, 2020 · 0 comments

Comments

@matburnham
Copy link

collection.find({}, 'name' ) raises a DeprecationWarning. I see #303/#304 fixed documentation by suggesting shifting to projection, rather than fields. This will no doubt work, but the documentation changes do not appear to fully reflect reality when using an options string.

findOne arguments documentation:

  1. [options] (Object|String|Array): If the options is a string, it will be parsed as the projections to select.

findOne example:

users.findOne({name: 'foo'}, 'name').then((doc) => {
  // only the name projection will be selected
});

Using monk 7.3.0, as expected findOne with fields raises a DeprecationWarning:

> collection.find({name: 'Test'}, { fields: { 'name': 1 } } );
> (node:125878) DeprecationWarning: collection.find option [fields] is deprecated and will be removed in a later version.

findOne with projections works with no issues:

> collection.findOne({name: 'Test'}, { projection: { 'name': 1 } } );
>

However, findOne appears to continue to parse an options string as fields, not projection as it raises an unexpected DeprecationWarning:

> collection.findOne({name: 'Test'}, 'name' );
> (node:126116) DeprecationWarning: collection.find option [fields] is deprecated and will be removed in a later version.

The same behaviour is experienced with find.

Is the options string expansion to fields done within monk or within mongodb? Either way, the problem should be fixed or the documentation updated to reflect reality.

This also affects the code in README.md which references passing options as a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant