mongoose 7.0.0 → 7.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +232 -0
- package/README.md +16 -16
- package/dist/browser.umd.js +1 -1
- package/lib/aggregate.js +2 -2
- package/lib/cast.js +1 -8
- package/lib/connection.js +10 -0
- package/lib/cursor/AggregationCursor.js +1 -1
- package/lib/cursor/QueryCursor.js +1 -1
- package/lib/document.js +24 -25
- package/lib/helpers/document/applyDefaults.js +1 -1
- package/lib/model.js +9 -11
- package/lib/query.js +3 -2
- package/lib/schema/documentarray.js +5 -3
- package/lib/schema/uuid.js +4 -1
- package/lib/schema.js +10 -3
- package/lib/schematype.js +1 -1
- package/package.json +15 -12
- package/scripts/generateSearch.js +32 -27
- package/types/cursor.d.ts +2 -2
- package/types/index.d.ts +8 -6
- package/types/models.d.ts +17 -2
- package/types/query.d.ts +2 -5
- package/types/types.d.ts +1 -1
- package/.eslintrc.json +0 -194
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
extends: [
|
|
5
|
+
'eslint:recommended'
|
|
6
|
+
],
|
|
7
|
+
ignorePatterns: [
|
|
8
|
+
'tools',
|
|
9
|
+
'dist',
|
|
10
|
+
'website.js',
|
|
11
|
+
'test/files/*',
|
|
12
|
+
'benchmarks',
|
|
13
|
+
'*.min.js',
|
|
14
|
+
'docs/js/native.js'
|
|
15
|
+
],
|
|
16
|
+
overrides: [
|
|
17
|
+
{
|
|
18
|
+
files: [
|
|
19
|
+
'**/*.{ts,tsx}',
|
|
20
|
+
'**/*.md/*.ts',
|
|
21
|
+
'**/*.md/*.typescript'
|
|
22
|
+
],
|
|
23
|
+
extends: [
|
|
24
|
+
'plugin:@typescript-eslint/eslint-recommended',
|
|
25
|
+
'plugin:@typescript-eslint/recommended'
|
|
26
|
+
],
|
|
27
|
+
plugins: [
|
|
28
|
+
'@typescript-eslint'
|
|
29
|
+
],
|
|
30
|
+
rules: {
|
|
31
|
+
'@typescript-eslint/triple-slash-reference': 'off',
|
|
32
|
+
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
33
|
+
'@typescript-eslint/no-empty-function': 'off',
|
|
34
|
+
'spaced-comment': [
|
|
35
|
+
'error',
|
|
36
|
+
'always',
|
|
37
|
+
{
|
|
38
|
+
block: {
|
|
39
|
+
markers: [
|
|
40
|
+
'!'
|
|
41
|
+
],
|
|
42
|
+
balanced: true
|
|
43
|
+
},
|
|
44
|
+
markers: [
|
|
45
|
+
'/'
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
50
|
+
'@typescript-eslint/ban-types': 'off',
|
|
51
|
+
'@typescript-eslint/no-unused-vars': 'off',
|
|
52
|
+
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
53
|
+
'@typescript-eslint/indent': [
|
|
54
|
+
'warn',
|
|
55
|
+
2,
|
|
56
|
+
{
|
|
57
|
+
SwitchCase: 1,
|
|
58
|
+
ignoredNodes: ['TSTypeParameterInstantiation']
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
'@typescript-eslint/prefer-optional-chain': 'error',
|
|
62
|
+
'@typescript-eslint/brace-style': 'error',
|
|
63
|
+
'@typescript-eslint/no-dupe-class-members': 'error',
|
|
64
|
+
'@typescript-eslint/no-redeclare': 'error',
|
|
65
|
+
'@typescript-eslint/type-annotation-spacing': 'error',
|
|
66
|
+
'@typescript-eslint/object-curly-spacing': [
|
|
67
|
+
'error',
|
|
68
|
+
'always'
|
|
69
|
+
],
|
|
70
|
+
'@typescript-eslint/semi': 'error',
|
|
71
|
+
'@typescript-eslint/space-before-function-paren': [
|
|
72
|
+
'error',
|
|
73
|
+
'never'
|
|
74
|
+
],
|
|
75
|
+
'@typescript-eslint/space-infix-ops': 'off'
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
files: [
|
|
80
|
+
'docs/js/**/*.js'
|
|
81
|
+
],
|
|
82
|
+
env: {
|
|
83
|
+
node: false,
|
|
84
|
+
browser: true
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// // eslint-plugin-markdown has been disabled because of out-standing issues, see https://github.com/eslint/eslint-plugin-markdown/issues/214
|
|
88
|
+
// {
|
|
89
|
+
// files: ['**/*.md'],
|
|
90
|
+
// processor: 'markdown/markdown'
|
|
91
|
+
// },
|
|
92
|
+
// {
|
|
93
|
+
// files: ['**/*.md/*.js', '**/*.md/*.javascript', '**/*.md/*.ts', '**/*.md/*.typescript'],
|
|
94
|
+
// parserOptions: {
|
|
95
|
+
// ecmaFeatures: {
|
|
96
|
+
// impliedStrict: true
|
|
97
|
+
// },
|
|
98
|
+
// sourceType: 'module', // required to allow "import" statements
|
|
99
|
+
// ecmaVersion: 'latest' // required to allow top-level await
|
|
100
|
+
// },
|
|
101
|
+
// rules: {
|
|
102
|
+
// 'no-undef': 'off',
|
|
103
|
+
// 'no-unused-expressions': 'off',
|
|
104
|
+
// 'no-unused-vars': 'off',
|
|
105
|
+
// 'no-redeclare': 'off',
|
|
106
|
+
// '@typescript-eslint/no-redeclare': 'off'
|
|
107
|
+
// }
|
|
108
|
+
// }
|
|
109
|
+
],
|
|
110
|
+
plugins: [
|
|
111
|
+
'mocha-no-only'
|
|
112
|
+
// 'markdown'
|
|
113
|
+
],
|
|
114
|
+
parserOptions: {
|
|
115
|
+
ecmaVersion: 2020
|
|
116
|
+
},
|
|
117
|
+
env: {
|
|
118
|
+
node: true,
|
|
119
|
+
es6: true
|
|
120
|
+
},
|
|
121
|
+
rules: {
|
|
122
|
+
'comma-style': 'error',
|
|
123
|
+
indent: [
|
|
124
|
+
'error',
|
|
125
|
+
2,
|
|
126
|
+
{
|
|
127
|
+
SwitchCase: 1,
|
|
128
|
+
VariableDeclarator: 2
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
'keyword-spacing': 'error',
|
|
132
|
+
'no-whitespace-before-property': 'error',
|
|
133
|
+
'no-buffer-constructor': 'warn',
|
|
134
|
+
'no-console': 'off',
|
|
135
|
+
'no-constant-condition': 'off',
|
|
136
|
+
'no-multi-spaces': 'error',
|
|
137
|
+
'func-call-spacing': 'error',
|
|
138
|
+
'no-trailing-spaces': 'error',
|
|
139
|
+
'no-undef': 'error',
|
|
140
|
+
'no-unneeded-ternary': 'error',
|
|
141
|
+
'no-const-assign': 'error',
|
|
142
|
+
'no-useless-rename': 'error',
|
|
143
|
+
'no-dupe-keys': 'error',
|
|
144
|
+
'space-in-parens': [
|
|
145
|
+
'error',
|
|
146
|
+
'never'
|
|
147
|
+
],
|
|
148
|
+
'spaced-comment': [
|
|
149
|
+
'error',
|
|
150
|
+
'always',
|
|
151
|
+
{
|
|
152
|
+
block: {
|
|
153
|
+
markers: [
|
|
154
|
+
'!'
|
|
155
|
+
],
|
|
156
|
+
balanced: true
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
],
|
|
160
|
+
'key-spacing': [
|
|
161
|
+
'error',
|
|
162
|
+
{
|
|
163
|
+
beforeColon: false,
|
|
164
|
+
afterColon: true
|
|
165
|
+
}
|
|
166
|
+
],
|
|
167
|
+
'comma-spacing': [
|
|
168
|
+
'error',
|
|
169
|
+
{
|
|
170
|
+
before: false,
|
|
171
|
+
after: true
|
|
172
|
+
}
|
|
173
|
+
],
|
|
174
|
+
'array-bracket-spacing': 1,
|
|
175
|
+
'arrow-spacing': [
|
|
176
|
+
'error',
|
|
177
|
+
{
|
|
178
|
+
before: true,
|
|
179
|
+
after: true
|
|
180
|
+
}
|
|
181
|
+
],
|
|
182
|
+
'object-curly-spacing': [
|
|
183
|
+
'error',
|
|
184
|
+
'always'
|
|
185
|
+
],
|
|
186
|
+
'comma-dangle': [
|
|
187
|
+
'error',
|
|
188
|
+
'never'
|
|
189
|
+
],
|
|
190
|
+
'no-unreachable': 'error',
|
|
191
|
+
quotes: [
|
|
192
|
+
'error',
|
|
193
|
+
'single'
|
|
194
|
+
],
|
|
195
|
+
'quote-props': [
|
|
196
|
+
'error',
|
|
197
|
+
'as-needed'
|
|
198
|
+
],
|
|
199
|
+
semi: 'error',
|
|
200
|
+
'no-extra-semi': 'error',
|
|
201
|
+
'semi-spacing': 'error',
|
|
202
|
+
'no-spaced-func': 'error',
|
|
203
|
+
'no-throw-literal': 'error',
|
|
204
|
+
'space-before-blocks': 'error',
|
|
205
|
+
'space-before-function-paren': [
|
|
206
|
+
'error',
|
|
207
|
+
'never'
|
|
208
|
+
],
|
|
209
|
+
'space-infix-ops': 'error',
|
|
210
|
+
'space-unary-ops': 'error',
|
|
211
|
+
'no-var': 'warn',
|
|
212
|
+
'prefer-const': 'warn',
|
|
213
|
+
strict: [
|
|
214
|
+
'error',
|
|
215
|
+
'global'
|
|
216
|
+
],
|
|
217
|
+
'no-restricted-globals': [
|
|
218
|
+
'error',
|
|
219
|
+
{
|
|
220
|
+
name: 'context',
|
|
221
|
+
message: 'Don\'t use Mocha\'s global context'
|
|
222
|
+
}
|
|
223
|
+
],
|
|
224
|
+
'no-prototype-builtins': 'off',
|
|
225
|
+
'mocha-no-only/mocha-no-only': [
|
|
226
|
+
'error'
|
|
227
|
+
],
|
|
228
|
+
'no-empty': 'off',
|
|
229
|
+
'eol-last': 'warn',
|
|
230
|
+
'no-multiple-empty-lines': ['warn', { max: 2 }]
|
|
231
|
+
}
|
|
232
|
+
};
|
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ Mongoose is a [MongoDB](https://www.mongodb.org/) object modeling tool designed
|
|
|
13
13
|
|
|
14
14
|
The official documentation website is [mongoosejs.com](http://mongoosejs.com/).
|
|
15
15
|
|
|
16
|
-
Mongoose
|
|
16
|
+
Mongoose 7.0.0 was released on February 27, 2023. You can find more details on [backwards breaking changes in 7.0.0 on our docs site](https://mongoosejs.com/docs/migrating_to_7.html).
|
|
17
17
|
|
|
18
18
|
## Support
|
|
19
19
|
|
|
@@ -61,7 +61,7 @@ import mongoose from 'mongoose';
|
|
|
61
61
|
Or, using [Deno's `createRequire()` for CommonJS support](https://deno.land/std@0.113.0/node/README.md?source=#commonjs-modules-loading) as follows.
|
|
62
62
|
|
|
63
63
|
```javascript
|
|
64
|
-
import { createRequire } from
|
|
64
|
+
import { createRequire } from 'https://deno.land/std/node/module.ts';
|
|
65
65
|
const require = createRequire(import.meta.url);
|
|
66
66
|
|
|
67
67
|
const mongoose = require('mongoose');
|
|
@@ -112,7 +112,7 @@ const BlogPost = new Schema({
|
|
|
112
112
|
author: ObjectId,
|
|
113
113
|
title: String,
|
|
114
114
|
body: String,
|
|
115
|
-
|
|
115
|
+
date: Date
|
|
116
116
|
});
|
|
117
117
|
```
|
|
118
118
|
|
|
@@ -141,12 +141,12 @@ const Comment = new Schema({
|
|
|
141
141
|
});
|
|
142
142
|
|
|
143
143
|
// a setter
|
|
144
|
-
Comment.path('name').set(function
|
|
144
|
+
Comment.path('name').set(function(v) {
|
|
145
145
|
return capitalize(v);
|
|
146
146
|
});
|
|
147
147
|
|
|
148
148
|
// middleware
|
|
149
|
-
Comment.pre('save', function
|
|
149
|
+
Comment.pre('save', function(next) {
|
|
150
150
|
notify(this.get('email'));
|
|
151
151
|
next();
|
|
152
152
|
});
|
|
@@ -181,7 +181,7 @@ Once we have our model, we can then instantiate it, and save it:
|
|
|
181
181
|
```js
|
|
182
182
|
const instance = new MyModel();
|
|
183
183
|
instance.my.key = 'hello';
|
|
184
|
-
instance.save(function
|
|
184
|
+
instance.save(function(err) {
|
|
185
185
|
//
|
|
186
186
|
});
|
|
187
187
|
```
|
|
@@ -189,7 +189,7 @@ instance.save(function (err) {
|
|
|
189
189
|
Or we can find documents from the same collection
|
|
190
190
|
|
|
191
191
|
```js
|
|
192
|
-
MyModel.find({}, function
|
|
192
|
+
MyModel.find({}, function(err, docs) {
|
|
193
193
|
// docs.forEach
|
|
194
194
|
});
|
|
195
195
|
```
|
|
@@ -197,8 +197,8 @@ MyModel.find({}, function (err, docs) {
|
|
|
197
197
|
You can also `findOne`, `findById`, `update`, etc.
|
|
198
198
|
|
|
199
199
|
```js
|
|
200
|
-
const instance = await MyModel.findOne({ ... });
|
|
201
|
-
console.log(instance.my.key);
|
|
200
|
+
const instance = await MyModel.findOne({ /* ... */ });
|
|
201
|
+
console.log(instance.my.key); // 'hello'
|
|
202
202
|
```
|
|
203
203
|
|
|
204
204
|
For more details check out [the docs](http://mongoosejs.com/docs/queries.html).
|
|
@@ -241,7 +241,7 @@ const post = new BlogPost();
|
|
|
241
241
|
// create a comment
|
|
242
242
|
post.comments.push({ title: 'My comment' });
|
|
243
243
|
|
|
244
|
-
post.save(function
|
|
244
|
+
post.save(function(err) {
|
|
245
245
|
if (!err) console.log('Success!');
|
|
246
246
|
});
|
|
247
247
|
```
|
|
@@ -249,10 +249,10 @@ post.save(function (err) {
|
|
|
249
249
|
The same goes for removing them:
|
|
250
250
|
|
|
251
251
|
```js
|
|
252
|
-
BlogPost.findById(myId, function
|
|
252
|
+
BlogPost.findById(myId, function(err, post) {
|
|
253
253
|
if (!err) {
|
|
254
254
|
post.comments[0].remove();
|
|
255
|
-
post.save(function
|
|
255
|
+
post.save(function(err) {
|
|
256
256
|
// do something
|
|
257
257
|
});
|
|
258
258
|
}
|
|
@@ -273,7 +273,7 @@ You can intercept method arguments via middleware.
|
|
|
273
273
|
For example, this would allow you to broadcast changes about your Documents every time someone `set`s a path in your Document to a new value:
|
|
274
274
|
|
|
275
275
|
```js
|
|
276
|
-
schema.pre('set', function
|
|
276
|
+
schema.pre('set', function(next, path, val, typel) {
|
|
277
277
|
// `this` is the current Document
|
|
278
278
|
this.emit('set', path, val);
|
|
279
279
|
|
|
@@ -285,13 +285,13 @@ schema.pre('set', function (next, path, val, typel) {
|
|
|
285
285
|
Moreover, you can mutate the incoming `method` arguments so that subsequent middleware see different values for those arguments. To do so, just pass the new values to `next`:
|
|
286
286
|
|
|
287
287
|
```js
|
|
288
|
-
.pre(method, function firstPre
|
|
288
|
+
schema.pre(method, function firstPre(next, methodArg1, methodArg2) {
|
|
289
289
|
// Mutate methodArg1
|
|
290
|
-
next(
|
|
290
|
+
next('altered-' + methodArg1.toString(), methodArg2);
|
|
291
291
|
});
|
|
292
292
|
|
|
293
293
|
// pre declaration is chainable
|
|
294
|
-
.pre(method, function secondPre
|
|
294
|
+
schema.pre(method, function secondPre(next, methodArg1, methodArg2) {
|
|
295
295
|
console.log(methodArg1);
|
|
296
296
|
// => 'altered-originalValOfMethodArg1'
|
|
297
297
|
|