Automattic / Automattic/mongoose

should we make mongoose global options explicit in code

Open
#8,979 2 comments 0 reactions 0 assignees View on GitHub
developer-experience
Dominant language
JavaScript
Stars
27.5k
Forks
4k
Avg merge
2d 7h
Merged PRs (30d)
35

Description

https://mongoosejs.com/docs/deprecations.html says:

```
// Make Mongoose use `findOneAndUpdate()`. Note that this option is `true`
// by default, you need to set it to false.
mongoose.set('useFindAndModify', false);
```

This implies that mongoose.get('useFindAndModify') is true by default, but it
is undefined by default which could be misleading.

### newIssue.js
```
#!/usr/bin/env node
'use strict';

const assert = require('assert');
const mongoose = require('mongoose');
const useFindAndModify = mongoose.get('useFindAndModify');
assert.strictEqual(useFindAndModify, true);
```

### output
```
issues: ./newIssue.js
assert.js:100
throw new AssertionError(obj);
^

AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
+ actual - expected

+ undefined
- true
at Object. (/home/lineus/old_dev/node/BE/mongoose/issues/8886_2.js:7:8)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: undefined,
expected: true,
operator: 'strictEqual'
}
issues:
```

Mongoose's **behavior** though is to treat the option as true by default, so in spirit it is correct.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the deprecations documentation and reproducing the example in newIssue.js to compare mongoose.get('useFindAndModify') with the documented default. Determine how the global option is defined and verify that the reported default is represented consistently in the API and documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb, nodejs
Domain
backend, 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.