Skip to content

DeprecationWarning raised when using a find options string #308

Open

Description

@matburnham

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions