mongoose 6.2.6 → 6.2.9
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.json +35 -26
- package/CHANGELOG.md +30 -0
- package/dist/browser.umd.js +83 -75
- package/lib/browserDocument.js +1 -0
- package/lib/connection.js +4 -4
- package/lib/cursor/AggregationCursor.js +0 -1
- package/lib/cursor/QueryCursor.js +2 -1
- package/lib/document.js +49 -11
- package/lib/helpers/document/handleSpreadDoc.js +19 -1
- package/lib/helpers/query/castFilterPath.js +0 -1
- package/lib/index.js +1 -3
- package/lib/model.js +78 -67
- package/lib/options/SchemaDateOptions.js +8 -1
- package/lib/query.js +41 -13
- package/lib/queryhelpers.js +17 -0
- package/lib/schema/SubdocumentPath.js +4 -1
- package/lib/schema/array.js +1 -0
- package/lib/schema/documentarray.js +14 -7
- package/lib/schema.js +14 -4
- package/lib/schematype.js +3 -1
- package/lib/types/array/methods/index.js +2 -0
- package/lib/virtualtype.js +1 -0
- package/package.json +12 -11
- package/tools/repl.js +8 -8
- package/tools/sharded.js +3 -3
- package/types/connection.d.ts +116 -116
- package/types/document.d.ts +3 -0
- package/types/error.d.ts +2 -2
- package/types/index.d.ts +73 -178
- package/types/mongooseoptions.d.ts +180 -0
- package/types/pipelinestage.d.ts +194 -194
- package/types/schemaoptions.d.ts +8 -2
|
@@ -12,6 +12,7 @@ const SchemaDocumentArrayOptions =
|
|
|
12
12
|
const SchemaType = require('../schematype');
|
|
13
13
|
const discriminator = require('../helpers/model/discriminator');
|
|
14
14
|
const handleIdOption = require('../helpers/schema/handleIdOption');
|
|
15
|
+
const handleSpreadDoc = require('../helpers/document/handleSpreadDoc');
|
|
15
16
|
const util = require('util');
|
|
16
17
|
const utils = require('../utils');
|
|
17
18
|
const getConstructor = require('../helpers/discriminator/getConstructor');
|
|
@@ -29,6 +30,7 @@ let Subdocument;
|
|
|
29
30
|
* @param {String} key
|
|
30
31
|
* @param {Schema} schema
|
|
31
32
|
* @param {Object} options
|
|
33
|
+
* @param {Object} schemaOptions
|
|
32
34
|
* @inherits SchemaArray
|
|
33
35
|
* @api public
|
|
34
36
|
*/
|
|
@@ -427,13 +429,18 @@ DocumentArrayPath.prototype.cast = function(value, doc, init, prev, options) {
|
|
|
427
429
|
const Constructor = getConstructor(this.casterConstructor, rawArray[i]);
|
|
428
430
|
|
|
429
431
|
// Check if the document has a different schema (re gh-3701)
|
|
430
|
-
if (rawArray[i].$__ && !(rawArray[i] instanceof Constructor)) {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
432
|
+
if (rawArray[i].$__ != null && !(rawArray[i] instanceof Constructor)) {
|
|
433
|
+
const spreadDoc = handleSpreadDoc(rawArray[i], true);
|
|
434
|
+
if (rawArray[i] !== spreadDoc) {
|
|
435
|
+
rawArray[i] = spreadDoc;
|
|
436
|
+
} else {
|
|
437
|
+
rawArray[i] = rawArray[i].toObject({
|
|
438
|
+
transform: false,
|
|
439
|
+
// Special case: if different model, but same schema, apply virtuals
|
|
440
|
+
// re: gh-7898
|
|
441
|
+
virtuals: rawArray[i].schema === Constructor.schema
|
|
442
|
+
});
|
|
443
|
+
}
|
|
437
444
|
}
|
|
438
445
|
|
|
439
446
|
if (rawArray[i] instanceof Subdocument) {
|
package/lib/schema.js
CHANGED
|
@@ -329,6 +329,10 @@ Schema.prototype.clone = function() {
|
|
|
329
329
|
return s;
|
|
330
330
|
};
|
|
331
331
|
|
|
332
|
+
/*!
|
|
333
|
+
* ignore
|
|
334
|
+
*/
|
|
335
|
+
|
|
332
336
|
Schema.prototype._clone = function _clone(Constructor) {
|
|
333
337
|
Constructor = Constructor || (this.base == null ? Schema : this.base.Schema);
|
|
334
338
|
|
|
@@ -961,8 +965,11 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
|
|
|
961
965
|
if (cast && cast.instanceOfSchema) {
|
|
962
966
|
if (!(cast instanceof Schema)) {
|
|
963
967
|
throw new TypeError('Schema for array path `' + path +
|
|
964
|
-
'` is from a different copy of the Mongoose module.
|
|
965
|
-
'
|
|
968
|
+
'` is from a different copy of the Mongoose module. ' +
|
|
969
|
+
'Please make sure you\'re using the same version ' +
|
|
970
|
+
'of Mongoose everywhere with `npm list mongoose`. If you are still ' +
|
|
971
|
+
'getting this error, please add `new Schema()` around the path: ' +
|
|
972
|
+
`${path}: new Schema(...)`);
|
|
966
973
|
}
|
|
967
974
|
return new MongooseTypes.DocumentArray(path, cast, obj);
|
|
968
975
|
}
|
|
@@ -971,8 +978,11 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
|
|
|
971
978
|
cast[options.typeKey].instanceOfSchema) {
|
|
972
979
|
if (!(cast[options.typeKey] instanceof Schema)) {
|
|
973
980
|
throw new TypeError('Schema for array path `' + path +
|
|
974
|
-
'` is from a different copy of the Mongoose module.
|
|
975
|
-
'
|
|
981
|
+
'` is from a different copy of the Mongoose module. ' +
|
|
982
|
+
'Please make sure you\'re using the same version ' +
|
|
983
|
+
'of Mongoose everywhere with `npm list mongoose`. If you are still ' +
|
|
984
|
+
'getting this error, please add `new Schema()` around the path: ' +
|
|
985
|
+
`${path}: new Schema(...)`);
|
|
976
986
|
}
|
|
977
987
|
return new MongooseTypes.DocumentArray(path, cast[options.typeKey], obj, cast);
|
|
978
988
|
}
|
package/lib/schematype.js
CHANGED
|
@@ -22,6 +22,8 @@ const populateModelSymbol = require('./helpers/symbols').populateModelSymbol;
|
|
|
22
22
|
const CastError = MongooseError.CastError;
|
|
23
23
|
const ValidatorError = MongooseError.ValidatorError;
|
|
24
24
|
|
|
25
|
+
const setOptionsForDefaults = { _skipMarkModified: true };
|
|
26
|
+
|
|
25
27
|
/**
|
|
26
28
|
* SchemaType constructor. Do **not** instantiate `SchemaType` directly.
|
|
27
29
|
* Mongoose converts your schema paths into SchemaTypes automatically.
|
|
@@ -1124,7 +1126,7 @@ SchemaType.prototype.getDefault = function(scope, init) {
|
|
|
1124
1126
|
ret = utils.clone(ret);
|
|
1125
1127
|
}
|
|
1126
1128
|
|
|
1127
|
-
const casted = this.applySetters(ret, scope, init);
|
|
1129
|
+
const casted = this.applySetters(ret, scope, init, undefined, setOptionsForDefaults);
|
|
1128
1130
|
if (casted && !Array.isArray(casted) && casted.$isSingleNested) {
|
|
1129
1131
|
casted.$__parent = scope;
|
|
1130
1132
|
}
|
|
@@ -445,6 +445,7 @@ const methods = {
|
|
|
445
445
|
* Return whether or not the `obj` is included in the array.
|
|
446
446
|
*
|
|
447
447
|
* @param {Object} obj the item to check
|
|
448
|
+
* @param {Number} fromIndex
|
|
448
449
|
* @return {Boolean}
|
|
449
450
|
* @api public
|
|
450
451
|
* @method includes
|
|
@@ -460,6 +461,7 @@ const methods = {
|
|
|
460
461
|
* Return the index of `obj` or `-1` if not found.
|
|
461
462
|
*
|
|
462
463
|
* @param {Object} obj the item to look for
|
|
464
|
+
* @param {Number} fromIndex
|
|
463
465
|
* @return {Number}
|
|
464
466
|
* @api public
|
|
465
467
|
* @method indexOf
|
package/lib/virtualtype.js
CHANGED
|
@@ -24,6 +24,7 @@ const utils = require('./utils');
|
|
|
24
24
|
* @param {Number} [options.skip=null] add a default `skip` to the `populate()` query
|
|
25
25
|
* @param {Number} [options.perDocumentLimit=null] For legacy reasons, `limit` with `populate()` may give incorrect results because it only executes a single query for every document being populated. If you set `perDocumentLimit`, Mongoose will ensure correct `limit` per document by executing a separate query for each document to `populate()`. For example, `.find().populate({ path: 'test', perDocumentLimit: 2 })` will execute 2 additional queries if `.find()` returns 2 documents.
|
|
26
26
|
* @param {Object} [options.options=null] Additional options like `limit` and `lean`.
|
|
27
|
+
* @param {string} name
|
|
27
28
|
* @api public
|
|
28
29
|
*/
|
|
29
30
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "6.2.
|
|
4
|
+
"version": "6.2.9",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"bson": "^4.2.2",
|
|
23
|
-
"kareem": "2.3.
|
|
23
|
+
"kareem": "2.3.5",
|
|
24
24
|
"mongodb": "4.3.1",
|
|
25
25
|
"mpath": "0.8.4",
|
|
26
26
|
"mquery": "4.0.2",
|
|
@@ -28,25 +28,26 @@
|
|
|
28
28
|
"sift": "16.0.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@babel/core": "7.17.
|
|
31
|
+
"@babel/core": "7.17.8",
|
|
32
32
|
"@babel/preset-env": "7.16.11",
|
|
33
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
34
|
-
"@typescript-eslint/parser": "5.
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "5.16.0",
|
|
34
|
+
"@typescript-eslint/parser": "5.16.0",
|
|
35
35
|
"acquit": "1.x",
|
|
36
36
|
"acquit-ignore": "0.2.x",
|
|
37
37
|
"acquit-require": "0.1.x",
|
|
38
|
-
"
|
|
38
|
+
"axios": "0.26.1",
|
|
39
|
+
"babel-loader": "8.2.4",
|
|
39
40
|
"benchmark": "2.1.4",
|
|
40
41
|
"bluebird": "3.7.2",
|
|
41
42
|
"cheerio": "1.0.0-rc.10",
|
|
42
43
|
"dox": "0.3.1",
|
|
43
|
-
"eslint": "8.
|
|
44
|
+
"eslint": "8.11.0",
|
|
44
45
|
"eslint-plugin-mocha-no-only": "1.1.1",
|
|
45
46
|
"highlight.js": "9.18.3",
|
|
46
47
|
"lodash.isequal": "4.5.0",
|
|
47
48
|
"lodash.isequalwith": "4.4.0",
|
|
48
|
-
"marked": "
|
|
49
|
-
"mocha": "9.2.
|
|
49
|
+
"marked": "4.0.12",
|
|
50
|
+
"mocha": "9.2.2",
|
|
50
51
|
"moment": "2.x",
|
|
51
52
|
"mongodb-memory-server": "^8.3.0",
|
|
52
53
|
"nyc": "^15.1.0",
|
|
@@ -54,7 +55,7 @@
|
|
|
54
55
|
"q": "1.5.1",
|
|
55
56
|
"serve-handler": "6.1.3",
|
|
56
57
|
"tsd": "0.19.1",
|
|
57
|
-
"typescript": "4.
|
|
58
|
+
"typescript": "4.6.3",
|
|
58
59
|
"uuid": "8.3.2",
|
|
59
60
|
"webpack": "4.44.1"
|
|
60
61
|
},
|
|
@@ -116,4 +117,4 @@
|
|
|
116
117
|
"target": "ES2017"
|
|
117
118
|
}
|
|
118
119
|
}
|
|
119
|
-
}
|
|
120
|
+
}
|
package/tools/repl.js
CHANGED
|
@@ -5,7 +5,7 @@ run().catch(error => {
|
|
|
5
5
|
process.exit(-1);
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
-
async function run
|
|
8
|
+
async function run() {
|
|
9
9
|
const ReplSet = require('mongodb-memory-server').MongoMemoryReplSet;
|
|
10
10
|
|
|
11
11
|
// Create new instance
|
|
@@ -15,20 +15,20 @@ async function run () {
|
|
|
15
15
|
},
|
|
16
16
|
instanceOpts: [
|
|
17
17
|
// Set the expiry job in MongoDB to run every second
|
|
18
|
-
{
|
|
18
|
+
{
|
|
19
19
|
port: 27017,
|
|
20
|
-
args: [
|
|
20
|
+
args: ['--setParameter', 'ttlMonitorSleepSecs=1'] }
|
|
21
21
|
],
|
|
22
22
|
dbName: 'mongoose_test',
|
|
23
23
|
replSet: {
|
|
24
|
-
name:
|
|
24
|
+
name: 'rs0',
|
|
25
25
|
count: 2,
|
|
26
|
-
storageEngine:
|
|
27
|
-
}
|
|
26
|
+
storageEngine: 'wiredTiger'
|
|
27
|
+
}
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
await replSet.start();
|
|
31
31
|
await replSet.waitUntilRunning();
|
|
32
|
-
console.log(
|
|
33
|
-
console.log(replSet.getUri(
|
|
32
|
+
console.log('MongoDB-ReplicaSet is now running.');
|
|
33
|
+
console.log(replSet.getUri('mongoose_test'));
|
|
34
34
|
}
|
package/tools/sharded.js
CHANGED
|
@@ -6,7 +6,7 @@ run().catch(error => {
|
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
async function run
|
|
9
|
+
async function run() {
|
|
10
10
|
const Sharded = require('mongodb-topology-manager').Sharded;
|
|
11
11
|
|
|
12
12
|
// Create new instance
|
|
@@ -17,13 +17,13 @@ async function run () {
|
|
|
17
17
|
|
|
18
18
|
await topology.addShard([{
|
|
19
19
|
options: {
|
|
20
|
-
bind_ip: 'localhost', port: 31000, dbpath:
|
|
20
|
+
bind_ip: 'localhost', port: 31000, dbpath: '/data/db/31000', shardsvr: null
|
|
21
21
|
}
|
|
22
22
|
}], { replSet: 'rs1' });
|
|
23
23
|
|
|
24
24
|
await topology.addConfigurationServers([{
|
|
25
25
|
options: {
|
|
26
|
-
bind_ip: 'localhost', port: 35000, dbpath:
|
|
26
|
+
bind_ip: 'localhost', port: 35000, dbpath: '/data/db/35000'
|
|
27
27
|
}
|
|
28
28
|
}], { replSet: 'rs0' });
|
|
29
29
|
|
package/types/connection.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import events = require('events');
|
|
|
3
3
|
|
|
4
4
|
declare module 'mongoose' {
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
7
|
* Connection ready state
|
|
8
8
|
*
|
|
9
9
|
* - 0 = disconnected
|
|
@@ -12,147 +12,147 @@ declare module 'mongoose' {
|
|
|
12
12
|
* - 3 = disconnecting
|
|
13
13
|
* - 99 = uninitialized
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
15
|
+
export enum ConnectionStates {
|
|
16
|
+
disconnected = 0,
|
|
17
|
+
connected = 1,
|
|
18
|
+
connecting = 2,
|
|
19
|
+
disconnecting = 3,
|
|
20
|
+
uninitialized = 99,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Expose connection states for user-land */
|
|
24
|
+
export const STATES: typeof ConnectionStates;
|
|
25
|
+
|
|
26
|
+
interface ConnectOptions extends mongodb.MongoClientOptions {
|
|
27
|
+
/** Set to false to [disable buffering](http://mongoosejs.com/docs/faq.html#callback_never_executes) on all models associated with this connection. */
|
|
28
|
+
bufferCommands?: boolean;
|
|
29
|
+
/** The name of the database you want to use. If not provided, Mongoose uses the database name from connection string. */
|
|
30
|
+
dbName?: string;
|
|
31
|
+
/** username for authentication, equivalent to `options.auth.user`. Maintained for backwards compatibility. */
|
|
32
|
+
user?: string;
|
|
33
|
+
/** password for authentication, equivalent to `options.auth.password`. Maintained for backwards compatibility. */
|
|
34
|
+
pass?: string;
|
|
35
|
+
/** Set to false to disable automatic index creation for all models associated with this connection. */
|
|
36
|
+
autoIndex?: boolean;
|
|
37
|
+
/** Set to `true` to make Mongoose automatically call `createCollection()` on every model created on this connection. */
|
|
38
|
+
autoCreate?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
class Connection extends events.EventEmitter {
|
|
42
|
+
/** Returns a promise that resolves when this connection successfully connects to MongoDB */
|
|
43
|
+
asPromise(): Promise<this>;
|
|
44
|
+
|
|
45
|
+
/** Closes the connection */
|
|
46
|
+
close(force: boolean, callback: CallbackWithoutResult): void;
|
|
47
|
+
close(callback: CallbackWithoutResult): void;
|
|
48
|
+
close(force?: boolean): Promise<void>;
|
|
49
|
+
|
|
50
|
+
/** Retrieves a collection, creating it if not cached. */
|
|
51
|
+
collection<T extends AnyObject = AnyObject>(name: string, options?: mongodb.CreateCollectionOptions): Collection<T>;
|
|
52
|
+
|
|
53
|
+
/** A hash of the collections associated with this connection */
|
|
54
|
+
readonly collections: { [index: string]: Collection };
|
|
55
|
+
|
|
56
|
+
/** A hash of the global options that are associated with this connection */
|
|
57
|
+
readonly config: any;
|
|
58
|
+
|
|
59
|
+
/** The mongodb.Db instance, set when the connection is opened */
|
|
60
|
+
readonly db: mongodb.Db;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
63
|
* Helper for `createCollection()`. Will explicitly create the given collection
|
|
64
64
|
* with specified options. Used to create [capped collections](https://docs.mongodb.com/manual/core/capped-collections/)
|
|
65
65
|
* and [views](https://docs.mongodb.com/manual/core/views/) from mongoose.
|
|
66
66
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
createCollection<T extends AnyObject = AnyObject>(name: string, options: mongodb.CreateCollectionOptions, callback: Callback<mongodb.Collection<T>>): void;
|
|
68
|
+
createCollection<T extends AnyObject = AnyObject>(name: string, callback: Callback<mongodb.Collection<T>>): void;
|
|
69
|
+
createCollection<T extends AnyObject = AnyObject>(name: string, options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection<T>>;
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
/**
|
|
72
72
|
* Removes the model named `name` from this connection, if it exists. You can
|
|
73
73
|
* use this function to clean up any models you created in your tests to
|
|
74
74
|
* prevent OverwriteModelErrors.
|
|
75
75
|
*/
|
|
76
|
-
|
|
76
|
+
deleteModel(name: string): this;
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
/**
|
|
79
79
|
* Helper for `dropCollection()`. Will delete the given collection, including
|
|
80
80
|
* all documents and indexes.
|
|
81
81
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
dropCollection(collection: string, callback: CallbackWithoutResult): void;
|
|
83
|
+
dropCollection(collection: string): Promise<void>;
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
/**
|
|
86
86
|
* Helper for `dropDatabase()`. Deletes the given database, including all
|
|
87
87
|
* collections, documents, and indexes.
|
|
88
88
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
dropDatabase(callback: CallbackWithoutResult): void;
|
|
90
|
+
dropDatabase(): Promise<void>;
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
/** Gets the value of the option `key`. */
|
|
93
|
+
get(key: string): any;
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
/**
|
|
96
96
|
* Returns the [MongoDB driver `MongoClient`](http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html) instance
|
|
97
97
|
* that this connection uses to talk to MongoDB.
|
|
98
98
|
*/
|
|
99
|
-
|
|
99
|
+
getClient(): mongodb.MongoClient;
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
/**
|
|
102
102
|
* The host name portion of the URI. If multiple hosts, such as a replica set,
|
|
103
103
|
* this will contain the first host name in the URI
|
|
104
104
|
*/
|
|
105
|
-
|
|
105
|
+
readonly host: string;
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
/**
|
|
108
108
|
* A number identifier for this connection. Used for debugging when
|
|
109
109
|
* you have [multiple connections](/docs/connections.html#multiple_connections).
|
|
110
110
|
*/
|
|
111
|
-
|
|
111
|
+
readonly id: number;
|
|
112
112
|
|
|
113
|
-
|
|
113
|
+
/**
|
|
114
114
|
* A [POJO](https://masteringjs.io/tutorials/fundamentals/pojo) containing
|
|
115
115
|
* a map from model names to models. Contains all models that have been
|
|
116
116
|
* added to this connection using [`Connection#model()`](/docs/api/connection.html#connection_Connection-model).
|
|
117
117
|
*/
|
|
118
|
-
|
|
118
|
+
readonly models: Readonly<{ [index: string]: Model<any> }>;
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
120
|
+
/** Defines or retrieves a model. */
|
|
121
|
+
model<T, U, TQueryHelpers = {}>(
|
|
122
|
+
name: string,
|
|
123
|
+
schema?: Schema<T, U, TQueryHelpers>,
|
|
124
|
+
collection?: string,
|
|
125
|
+
options?: CompileModelOptions
|
|
126
|
+
): U;
|
|
127
|
+
model<T>(name: string, schema?: Schema<T>, collection?: string, options?: CompileModelOptions): Model<T>;
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
/** Returns an array of model names created on this connection. */
|
|
130
|
+
modelNames(): Array<string>;
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
/** The name of the database this connection points to. */
|
|
133
|
+
readonly name: string;
|
|
134
134
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
/** Opens the connection with a URI using `MongoClient.connect()`. */
|
|
136
|
+
openUri(uri: string, options: ConnectOptions, callback: Callback<Connection>): Connection;
|
|
137
|
+
openUri(uri: string, callback: Callback<Connection>): Connection;
|
|
138
|
+
openUri(uri: string, options?: ConnectOptions): Promise<Connection>;
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
/** The password specified in the URI */
|
|
141
|
+
readonly pass: string;
|
|
142
142
|
|
|
143
|
-
|
|
143
|
+
/**
|
|
144
144
|
* The port portion of the URI. If multiple hosts, such as a replica set,
|
|
145
145
|
* this will contain the port from the first host name in the URI.
|
|
146
146
|
*/
|
|
147
|
-
|
|
147
|
+
readonly port: number;
|
|
148
148
|
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
/** Declares a plugin executed on all schemas you pass to `conn.model()` */
|
|
150
|
+
plugin<S extends Schema = Schema, O = AnyObject>(fn: (schema: S, opts?: any) => void, opts?: O): Connection;
|
|
151
151
|
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
/** The plugins that will be applied to all models created on this connection. */
|
|
153
|
+
plugins: Array<any>;
|
|
154
154
|
|
|
155
|
-
|
|
155
|
+
/**
|
|
156
156
|
* Connection ready state
|
|
157
157
|
*
|
|
158
158
|
* - 0 = disconnected
|
|
@@ -161,52 +161,52 @@ declare module 'mongoose' {
|
|
|
161
161
|
* - 3 = disconnecting
|
|
162
162
|
* - 99 = uninitialized
|
|
163
163
|
*/
|
|
164
|
-
|
|
164
|
+
readonly readyState: ConnectionStates;
|
|
165
165
|
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
/** Sets the value of the option `key`. */
|
|
167
|
+
set(key: string, value: any): any;
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
/**
|
|
170
170
|
* Set the [MongoDB driver `MongoClient`](http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html) instance
|
|
171
171
|
* that this connection uses to talk to MongoDB. This is useful if you already have a MongoClient instance, and want to
|
|
172
172
|
* reuse it.
|
|
173
173
|
*/
|
|
174
|
-
|
|
174
|
+
setClient(client: mongodb.MongoClient): this;
|
|
175
175
|
|
|
176
|
-
|
|
176
|
+
/**
|
|
177
177
|
* _Requires MongoDB >= 3.6.0._ Starts a [MongoDB session](https://docs.mongodb.com/manual/release-notes/3.6/#client-sessions)
|
|
178
178
|
* for benefits like causal consistency, [retryable writes](https://docs.mongodb.com/manual/core/retryable-writes/),
|
|
179
179
|
* and [transactions](http://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html).
|
|
180
180
|
*/
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
181
|
+
startSession(options: mongodb.ClientSessionOptions | undefined | null, callback: Callback<mongodb.ClientSession>): void;
|
|
182
|
+
startSession(callback: Callback<mongodb.ClientSession>): void;
|
|
183
|
+
startSession(options?: mongodb.ClientSessionOptions): Promise<mongodb.ClientSession>;
|
|
184
184
|
|
|
185
|
-
|
|
185
|
+
/**
|
|
186
186
|
* Makes the indexes in MongoDB match the indexes defined in every model's
|
|
187
187
|
* schema. This function will drop any indexes that are not defined in
|
|
188
188
|
* the model's schema except the `_id` index, and build any indexes that
|
|
189
189
|
* are in your schema but not in MongoDB.
|
|
190
190
|
*/
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
syncIndexes(options: SyncIndexesOptions | undefined | null, callback: Callback<ConnectionSyncIndexesResult>): void;
|
|
192
|
+
syncIndexes(options?: SyncIndexesOptions): Promise<ConnectionSyncIndexesResult>;
|
|
193
193
|
|
|
194
|
-
|
|
194
|
+
/**
|
|
195
195
|
* _Requires MongoDB >= 3.6.0._ Executes the wrapped async function
|
|
196
196
|
* in a transaction. Mongoose will commit the transaction if the
|
|
197
197
|
* async function executes successfully and attempt to retry if
|
|
198
198
|
* there was a retryable error.
|
|
199
199
|
*/
|
|
200
|
-
|
|
200
|
+
transaction<U = any>(fn: (session: mongodb.ClientSession) => Promise<U>): Promise<U>;
|
|
201
201
|
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
/** Switches to a different database using the same connection pool. */
|
|
203
|
+
useDb(name: string, options?: { useCache?: boolean, noListener?: boolean }): Connection;
|
|
204
204
|
|
|
205
|
-
|
|
206
|
-
|
|
205
|
+
/** The username specified in the URI */
|
|
206
|
+
readonly user: string;
|
|
207
207
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
208
|
+
/** Watches the entire underlying database for changes. Similar to [`Model.watch()`](/docs/api/model.html#model_Model.watch). */
|
|
209
|
+
watch<ResultType = any>(pipeline?: Array<any>, options?: mongodb.ChangeStreamOptions): mongodb.ChangeStream<ResultType>;
|
|
210
|
+
}
|
|
211
211
|
|
|
212
212
|
}
|
package/types/document.d.ts
CHANGED
|
@@ -169,6 +169,9 @@ declare module 'mongoose' {
|
|
|
169
169
|
/** The name of the model */
|
|
170
170
|
modelName: string;
|
|
171
171
|
|
|
172
|
+
/** Returns the model with the given name on this document's associated connection. */
|
|
173
|
+
model<ModelType = Model<unknown>>(name: string): ModelType;
|
|
174
|
+
|
|
172
175
|
/**
|
|
173
176
|
* Overwrite all values in this document with the values of `obj`, except
|
|
174
177
|
* for immutable properties. Behaves similarly to `set()`, except for it
|
package/types/error.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import mongodb = require('mongodb');
|
|
|
2
2
|
|
|
3
3
|
declare module 'mongoose' {
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
class NativeError extends global.Error { }
|
|
6
6
|
type CallbackError = NativeError | null;
|
|
7
7
|
|
|
8
8
|
class MongooseError extends global.Error {
|
|
@@ -126,4 +126,4 @@ declare module 'mongoose' {
|
|
|
126
126
|
constructor(doc: Document, currentVersion: number, modifiedPaths: Array<string>);
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
-
|
|
129
|
+
}
|