mongoplusplus 1.0.9 → 1.0.10
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/index.d.ts +12 -2
- package/mongoplus.js +11 -7
- package/package.json +1 -1
- package/test.js +0 -1
package/index.d.ts
CHANGED
|
@@ -28,7 +28,12 @@ declare class Mongoplus {
|
|
|
28
28
|
* const mp = new Mongoplus(['mongodb://a/db','readonly:mongodb://b/db']);
|
|
29
29
|
*/
|
|
30
30
|
constructor(mongoURI: string[]);
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Return the types of mongoose.
|
|
33
|
+
* @example
|
|
34
|
+
* const types = mp.types;
|
|
35
|
+
*/
|
|
36
|
+
get types(): mongoose.Schema.Types;
|
|
32
37
|
/**
|
|
33
38
|
* Create a mongoose Schema.
|
|
34
39
|
* @example
|
|
@@ -74,7 +79,12 @@ declare class MongoModel {
|
|
|
74
79
|
s: mongoose.Schema;
|
|
75
80
|
/** Rotation index for `write`. */
|
|
76
81
|
static currentIndex: number;
|
|
77
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Return the types of mongoose.
|
|
84
|
+
* @example
|
|
85
|
+
* const types = mm.types;
|
|
86
|
+
*/
|
|
87
|
+
get types(): mongoose.Schema.Types;
|
|
78
88
|
/**
|
|
79
89
|
* Construct a MongoModel.
|
|
80
90
|
* @example
|
package/mongoplus.js
CHANGED
|
@@ -14,7 +14,9 @@ class Mongoplus {
|
|
|
14
14
|
|
|
15
15
|
static readonlydbs = []
|
|
16
16
|
static readonlymodels = []
|
|
17
|
-
|
|
17
|
+
get types() {
|
|
18
|
+
return mongoose.Schema.Types
|
|
19
|
+
}
|
|
18
20
|
Schema(schema) {
|
|
19
21
|
return mongoose.Schema(schema)
|
|
20
22
|
}
|
|
@@ -89,7 +91,9 @@ class MongoModel {
|
|
|
89
91
|
}
|
|
90
92
|
|
|
91
93
|
static currentIndex = 0
|
|
92
|
-
|
|
94
|
+
get types() {
|
|
95
|
+
return mongoose.Schema.Types
|
|
96
|
+
}
|
|
93
97
|
async findInAllDatabase(filter, chain = {}) {
|
|
94
98
|
const dynamicComputationPromises = [];
|
|
95
99
|
this.model.forEach((modelRef) => {
|
|
@@ -122,7 +126,7 @@ class MongoModel {
|
|
|
122
126
|
async UpdateOneInAllDatabase(filter, update) {
|
|
123
127
|
const dynamicComputationPromises = [];
|
|
124
128
|
this.model.forEach((modelRef) => {
|
|
125
|
-
dynamicComputationPromises.push({ fn: modelRef.findOneAndUpdate.bind(modelRef), params: [filter, update, {
|
|
129
|
+
dynamicComputationPromises.push({ fn: modelRef.findOneAndUpdate.bind(modelRef), params: [filter, update, { returnDocument: 'after' }], chain: {} });
|
|
126
130
|
});
|
|
127
131
|
return await this.runLargeComputations(dynamicComputationPromises);
|
|
128
132
|
}
|
|
@@ -130,7 +134,7 @@ class MongoModel {
|
|
|
130
134
|
async UpdateByIdInAllDatabase(id, update) {
|
|
131
135
|
const dynamicComputationPromises = [];
|
|
132
136
|
this.model.forEach((modelRef) => {
|
|
133
|
-
dynamicComputationPromises.push({ fn: modelRef.findByIdAndUpdate.bind(modelRef), params: [id, update, {
|
|
137
|
+
dynamicComputationPromises.push({ fn: modelRef.findByIdAndUpdate.bind(modelRef), params: [id, update, { returnDocument: 'after' }], chain: {} });
|
|
134
138
|
});
|
|
135
139
|
return await this.runLargeComputations(dynamicComputationPromises);
|
|
136
140
|
}
|
|
@@ -382,18 +386,18 @@ class MongoModel {
|
|
|
382
386
|
|
|
383
387
|
async findByIdAndUpdate(dbIndex, id, update) {
|
|
384
388
|
var currentModel = this.model[dbIndex]
|
|
385
|
-
return currentModel.findByIdAndUpdate(id, update, {
|
|
389
|
+
return currentModel.findByIdAndUpdate(id, update, { returnDocument: 'after' });
|
|
386
390
|
}
|
|
387
391
|
|
|
388
392
|
async findByIdAndDelete(dbIndex, id) {
|
|
389
393
|
var currentModel = this.model[dbIndex]
|
|
390
394
|
// Changed from findByIdAndRemove to findByIdAndDelete (Mongoose 8 removed findByIdAndRemove)
|
|
391
|
-
return currentModel.findByIdAndDelete(id, {
|
|
395
|
+
return currentModel.findByIdAndDelete(id, { returnDocument: 'after' });
|
|
392
396
|
}
|
|
393
397
|
|
|
394
398
|
async findOneAndUpdate(dbIndex, filter, update) {
|
|
395
399
|
var currentModel = this.model[dbIndex]
|
|
396
|
-
return currentModel.findOneAndUpdate(filter, update, {
|
|
400
|
+
return currentModel.findOneAndUpdate(filter, update, { returnDocument: 'after' });
|
|
397
401
|
}
|
|
398
402
|
|
|
399
403
|
async aggregate(dbIndex, filter, update) {
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -16,7 +16,6 @@ async function performanceComparison() {
|
|
|
16
16
|
age: Number,
|
|
17
17
|
dbIndex: { type: Number, required: true }
|
|
18
18
|
});
|
|
19
|
-
|
|
20
19
|
const UserModel = mongoplus.buildModel('UserBulkWrite', schema);
|
|
21
20
|
const testData = Array.from({ length: 10000 }, (_, i) => ({
|
|
22
21
|
name: `User ${i}`,
|