Automattic / Automattic/monk

DeprecationWarning raised when using a find options string

Open
#308 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.8k
Forks
180
PR merge metrics
No merged PRs in 30d

Description

`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 ](https://automattic.github.io/monk/docs/collection/findOne.html#arguments)documentation:
> 2. [`options`] *(Object|String|Array)*: If the `options` is a string, it will be parsed as the projections to select.

`findOne` [example](https://automattic.github.io/monk/docs/collection/findOne.html#example):
```js
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`](https://github.com/Automattic/monk/blob/master/README.md) which references passing options as a string.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing how the find and findOne entry points expand a string options argument, then reproduce the DeprecationWarning described in the issue. Review the linked findOne documentation and README.md for the stated string behavior. Done means either string projections work without the unexpected warning or the documentation accurately describes the observed behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.