mongoose 8.13.2 → 8.13.3
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/dist/browser.umd.js +1 -1
- package/lib/error/index.js +23 -13
- package/lib/query.js +10 -12
- package/lib/utils.js +33 -7
- package/package.json +1 -1
- package/types/aggregate.d.ts +1 -1
- package/types/connection.d.ts +22 -0
- package/types/error.d.ts +7 -0
package/lib/error/index.js
CHANGED
|
@@ -65,32 +65,32 @@ MongooseError.messages = require('./messages');
|
|
|
65
65
|
MongooseError.Messages = MongooseError.messages;
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
* An instance of this error class will be
|
|
69
|
-
*
|
|
70
|
-
* document was not found. The constructor takes one parameter, the
|
|
71
|
-
* conditions that mongoose passed to `updateOne()` when trying to update
|
|
72
|
-
* the document.
|
|
68
|
+
* An instance of this error class will be thrown when mongoose failed to
|
|
69
|
+
* cast a value.
|
|
73
70
|
*
|
|
74
71
|
* @api public
|
|
75
72
|
* @memberOf Error
|
|
76
73
|
* @static
|
|
77
74
|
*/
|
|
78
75
|
|
|
79
|
-
MongooseError.
|
|
76
|
+
MongooseError.CastError = require('./cast');
|
|
80
77
|
|
|
81
78
|
/**
|
|
82
|
-
* An instance of this error class will be
|
|
83
|
-
*
|
|
79
|
+
* An instance of this error class will be thrown when `save()` fails
|
|
80
|
+
* because the underlying
|
|
81
|
+
* document was not found. The constructor takes one parameter, the
|
|
82
|
+
* conditions that mongoose passed to `updateOne()` when trying to update
|
|
83
|
+
* the document.
|
|
84
84
|
*
|
|
85
85
|
* @api public
|
|
86
86
|
* @memberOf Error
|
|
87
87
|
* @static
|
|
88
88
|
*/
|
|
89
89
|
|
|
90
|
-
MongooseError.
|
|
90
|
+
MongooseError.DocumentNotFoundError = require('./notFound');
|
|
91
91
|
|
|
92
92
|
/**
|
|
93
|
-
* An instance of this error class will be
|
|
93
|
+
* An instance of this error class will be thrown when [validation](https://mongoosejs.com/docs/validation.html) failed.
|
|
94
94
|
* The `errors` property contains an object whose keys are the paths that failed and whose values are
|
|
95
95
|
* instances of CastError or ValidationError.
|
|
96
96
|
*
|
|
@@ -137,7 +137,7 @@ MongooseError.ValidationError = require('./validation');
|
|
|
137
137
|
MongooseError.ValidatorError = require('./validator');
|
|
138
138
|
|
|
139
139
|
/**
|
|
140
|
-
* An instance of this error class will be
|
|
140
|
+
* An instance of this error class will be thrown when you call `save()` after
|
|
141
141
|
* the document in the database was changed in a potentially unsafe way. See
|
|
142
142
|
* the [`versionKey` option](https://mongoosejs.com/docs/guide.html#versionKey) for more information.
|
|
143
143
|
*
|
|
@@ -149,7 +149,7 @@ MongooseError.ValidatorError = require('./validator');
|
|
|
149
149
|
MongooseError.VersionError = require('./version');
|
|
150
150
|
|
|
151
151
|
/**
|
|
152
|
-
* An instance of this error class will be
|
|
152
|
+
* An instance of this error class will be thrown when you call `save()` multiple
|
|
153
153
|
* times on the same document in parallel. See the [FAQ](https://mongoosejs.com/docs/faq.html) for more
|
|
154
154
|
* information.
|
|
155
155
|
*
|
|
@@ -181,6 +181,16 @@ MongooseError.OverwriteModelError = require('./overwriteModel');
|
|
|
181
181
|
|
|
182
182
|
MongooseError.MissingSchemaError = require('./missingSchema');
|
|
183
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Thrown when some documents failed to save when calling `bulkSave()`
|
|
186
|
+
*
|
|
187
|
+
* @api public
|
|
188
|
+
* @memberOf Error
|
|
189
|
+
* @static
|
|
190
|
+
*/
|
|
191
|
+
|
|
192
|
+
MongooseError.MongooseBulkSaveIncompleteError = require('./bulkSaveIncompleteError');
|
|
193
|
+
|
|
184
194
|
/**
|
|
185
195
|
* Thrown when the MongoDB Node driver can't connect to a valid server
|
|
186
196
|
* to send an operation to.
|
|
@@ -193,7 +203,7 @@ MongooseError.MissingSchemaError = require('./missingSchema');
|
|
|
193
203
|
MongooseError.MongooseServerSelectionError = require('./serverSelection');
|
|
194
204
|
|
|
195
205
|
/**
|
|
196
|
-
* An instance of this error will be
|
|
206
|
+
* An instance of this error will be thrown if you used an array projection
|
|
197
207
|
* and then modified the array in an unsafe way.
|
|
198
208
|
*
|
|
199
209
|
* @api public
|
package/lib/query.js
CHANGED
|
@@ -3096,13 +3096,12 @@ function _handleSortValue(val, key) {
|
|
|
3096
3096
|
*
|
|
3097
3097
|
* await Character.deleteOne({ name: 'Eddard Stark' });
|
|
3098
3098
|
*
|
|
3099
|
-
* This function calls the MongoDB driver's [`Collection#deleteOne()` function](https://mongodb.github.io/node-mongodb-native/
|
|
3099
|
+
* This function calls the MongoDB driver's [`Collection#deleteOne()` function](https://mongodb.github.io/node-mongodb-native/6.15/classes/Collection.html#deleteOne).
|
|
3100
3100
|
* The returned [promise](https://mongoosejs.com/docs/queries.html) resolves to an
|
|
3101
|
-
* object that contains
|
|
3101
|
+
* object that contains 2 properties:
|
|
3102
3102
|
*
|
|
3103
|
-
* - `
|
|
3103
|
+
* - `acknowledged`: boolean
|
|
3104
3104
|
* - `deletedCount`: the number of documents deleted
|
|
3105
|
-
* - `n`: the number of documents deleted. Equal to `deletedCount`.
|
|
3106
3105
|
*
|
|
3107
3106
|
* #### Example:
|
|
3108
3107
|
*
|
|
@@ -3113,8 +3112,8 @@ function _handleSortValue(val, key) {
|
|
|
3113
3112
|
* @param {Object|Query} [filter] mongodb selector
|
|
3114
3113
|
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
3115
3114
|
* @return {Query} this
|
|
3116
|
-
* @see DeleteResult https://mongodb.github.io/node-mongodb-native/
|
|
3117
|
-
* @see deleteOne https://mongodb.github.io/node-mongodb-native/
|
|
3115
|
+
* @see DeleteResult https://mongodb.github.io/node-mongodb-native/6.15/interfaces/DeleteResult.html
|
|
3116
|
+
* @see deleteOne https://mongodb.github.io/node-mongodb-native/6.15/classes/Collection.html#deleteOne
|
|
3118
3117
|
* @api public
|
|
3119
3118
|
*/
|
|
3120
3119
|
|
|
@@ -3169,13 +3168,12 @@ Query.prototype._deleteOne = async function _deleteOne() {
|
|
|
3169
3168
|
*
|
|
3170
3169
|
* await Character.deleteMany({ name: /Stark/, age: { $gte: 18 } });
|
|
3171
3170
|
*
|
|
3172
|
-
* This function calls the MongoDB driver's [`Collection#deleteMany()` function](https://mongodb.github.io/node-mongodb-native/
|
|
3171
|
+
* This function calls the MongoDB driver's [`Collection#deleteMany()` function](https://mongodb.github.io/node-mongodb-native/6.15/classes/Collection.html#deleteMany).
|
|
3173
3172
|
* The returned [promise](https://mongoosejs.com/docs/queries.html) resolves to an
|
|
3174
|
-
* object that contains
|
|
3173
|
+
* object that contains 2 properties:
|
|
3175
3174
|
*
|
|
3176
|
-
* - `
|
|
3175
|
+
* - `acknowledged`: boolean
|
|
3177
3176
|
* - `deletedCount`: the number of documents deleted
|
|
3178
|
-
* - `n`: the number of documents deleted. Equal to `deletedCount`.
|
|
3179
3177
|
*
|
|
3180
3178
|
* #### Example:
|
|
3181
3179
|
*
|
|
@@ -3186,8 +3184,8 @@ Query.prototype._deleteOne = async function _deleteOne() {
|
|
|
3186
3184
|
* @param {Object|Query} [filter] mongodb selector
|
|
3187
3185
|
* @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.setOptions())
|
|
3188
3186
|
* @return {Query} this
|
|
3189
|
-
* @see DeleteResult https://mongodb.github.io/node-mongodb-native/
|
|
3190
|
-
* @see deleteMany https://mongodb.github.io/node-mongodb-native/
|
|
3187
|
+
* @see DeleteResult https://mongodb.github.io/node-mongodb-native/6.15/interfaces/DeleteResult.html
|
|
3188
|
+
* @see deleteMany https://mongodb.github.io/node-mongodb-native/6.15/classes/Collection.html#deleteMany
|
|
3191
3189
|
* @api public
|
|
3192
3190
|
*/
|
|
3193
3191
|
|
package/lib/utils.js
CHANGED
|
@@ -234,6 +234,38 @@ exports.omit = function omit(obj, keys) {
|
|
|
234
234
|
return ret;
|
|
235
235
|
};
|
|
236
236
|
|
|
237
|
+
/**
|
|
238
|
+
* Simplified version of `clone()` that only clones POJOs and arrays. Skips documents, dates, objectids, etc.
|
|
239
|
+
* @param {*} val
|
|
240
|
+
* @returns
|
|
241
|
+
*/
|
|
242
|
+
|
|
243
|
+
exports.clonePOJOsAndArrays = function clonePOJOsAndArrays(val) {
|
|
244
|
+
if (val == null) {
|
|
245
|
+
return val;
|
|
246
|
+
}
|
|
247
|
+
// Skip documents because we assume they'll be cloned later. See gh-15312 for how documents are handled with `merge()`.
|
|
248
|
+
if (val.$__ != null) {
|
|
249
|
+
return val;
|
|
250
|
+
}
|
|
251
|
+
if (isPOJO(val)) {
|
|
252
|
+
val = { ...val };
|
|
253
|
+
for (const key of Object.keys(val)) {
|
|
254
|
+
val[key] = exports.clonePOJOsAndArrays(val[key]);
|
|
255
|
+
}
|
|
256
|
+
return val;
|
|
257
|
+
}
|
|
258
|
+
if (Array.isArray(val)) {
|
|
259
|
+
val = [...val];
|
|
260
|
+
for (let i = 0; i < val.length; ++i) {
|
|
261
|
+
val[i] = exports.clonePOJOsAndArrays(val[i]);
|
|
262
|
+
}
|
|
263
|
+
return val;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return val;
|
|
267
|
+
};
|
|
268
|
+
|
|
237
269
|
/**
|
|
238
270
|
* Merges `from` into `to` without overwriting existing properties.
|
|
239
271
|
*
|
|
@@ -271,13 +303,7 @@ exports.merge = function merge(to, from, options, path) {
|
|
|
271
303
|
continue;
|
|
272
304
|
}
|
|
273
305
|
if (to[key] == null) {
|
|
274
|
-
|
|
275
|
-
to[key] = { ...from[key] };
|
|
276
|
-
} else if (Array.isArray(from[key])) {
|
|
277
|
-
to[key] = [...from[key]];
|
|
278
|
-
} else {
|
|
279
|
-
to[key] = from[key];
|
|
280
|
-
}
|
|
306
|
+
to[key] = exports.clonePOJOsAndArrays(from[key]);
|
|
281
307
|
} else if (exports.isObject(from[key])) {
|
|
282
308
|
if (!exports.isObject(to[key])) {
|
|
283
309
|
to[key] = {};
|
package/package.json
CHANGED
package/types/aggregate.d.ts
CHANGED
|
@@ -124,7 +124,7 @@ declare module 'mongoose' {
|
|
|
124
124
|
pipeline(): PipelineStage[];
|
|
125
125
|
|
|
126
126
|
/** Appends a new $project operator to this aggregate pipeline. */
|
|
127
|
-
project(arg: PipelineStage.Project['$project']): this;
|
|
127
|
+
project(arg: PipelineStage.Project['$project'] | string): this;
|
|
128
128
|
|
|
129
129
|
/** Sets the readPreference option for the aggregation query. */
|
|
130
130
|
read(pref: mongodb.ReadPreferenceLike): this;
|
package/types/connection.d.ts
CHANGED
|
@@ -58,12 +58,34 @@ declare module 'mongoose' {
|
|
|
58
58
|
sanitizeFilter?: boolean;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
export type AnyConnectionBulkWriteModel<TSchema extends AnyObject> = Omit<mongodb.ClientInsertOneModel<TSchema>, 'namespace'>
|
|
62
|
+
| Omit<mongodb.ClientReplaceOneModel<TSchema>, 'namespace'>
|
|
63
|
+
| Omit<mongodb.ClientUpdateOneModel<TSchema>, 'namespace'>
|
|
64
|
+
| Omit<mongodb.ClientUpdateManyModel<TSchema>, 'namespace'>
|
|
65
|
+
| Omit<mongodb.ClientDeleteOneModel<TSchema>, 'namespace'>
|
|
66
|
+
| Omit<mongodb.ClientDeleteManyModel<TSchema>, 'namespace'>;
|
|
67
|
+
|
|
68
|
+
export type ConnectionBulkWriteModel<SchemaMap extends Record<string, AnyObject> = Record<string, AnyObject>> = {
|
|
69
|
+
[ModelName in keyof SchemaMap]: AnyConnectionBulkWriteModel<SchemaMap[ModelName]> & {
|
|
70
|
+
model: ModelName;
|
|
71
|
+
};
|
|
72
|
+
}[keyof SchemaMap];
|
|
73
|
+
|
|
61
74
|
class Connection extends events.EventEmitter implements SessionStarter {
|
|
62
75
|
aggregate<ResultType = unknown>(pipeline?: PipelineStage[] | null, options?: AggregateOptions): Aggregate<Array<ResultType>>;
|
|
63
76
|
|
|
64
77
|
/** Returns a promise that resolves when this connection successfully connects to MongoDB */
|
|
65
78
|
asPromise(): Promise<this>;
|
|
66
79
|
|
|
80
|
+
bulkWrite<TSchemaMap extends Record<string, AnyObject>>(
|
|
81
|
+
ops: Array<ConnectionBulkWriteModel<TSchemaMap>>,
|
|
82
|
+
options: mongodb.ClientBulkWriteOptions & { ordered: false }
|
|
83
|
+
): Promise<mongodb.ClientBulkWriteResult & { mongoose?: { validationErrors: Error[], results: Array<Error | mongodb.WriteError | null> } }>;
|
|
84
|
+
bulkWrite<TSchemaMap extends Record<string, AnyObject>>(
|
|
85
|
+
ops: Array<ConnectionBulkWriteModel<TSchemaMap>>,
|
|
86
|
+
options?: mongodb.ClientBulkWriteOptions
|
|
87
|
+
): Promise<mongodb.ClientBulkWriteResult>;
|
|
88
|
+
|
|
67
89
|
/** Closes the connection */
|
|
68
90
|
close(force?: boolean): Promise<void>;
|
|
69
91
|
|
package/types/error.d.ts
CHANGED
|
@@ -129,5 +129,12 @@ declare module 'mongoose' {
|
|
|
129
129
|
name: 'StrictPopulateError';
|
|
130
130
|
path: string;
|
|
131
131
|
}
|
|
132
|
+
|
|
133
|
+
export class MongooseBulkSaveIncompleteError extends MongooseError {
|
|
134
|
+
name: 'MongooseBulkSaveIncompleteError';
|
|
135
|
+
modelName: string;
|
|
136
|
+
bulkWriteResult: mongodb.BulkWriteResult;
|
|
137
|
+
numDocumentsNotUpdated: number;
|
|
138
|
+
}
|
|
132
139
|
}
|
|
133
140
|
}
|