mongoplusplus 1.0.8 → 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 +14 -13
- package/package.json +2 -2
- 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
|
}
|
|
@@ -32,15 +34,12 @@ class Mongoplus {
|
|
|
32
34
|
return uri;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
connectToAll() {
|
|
37
|
+
connectToAll(connectionOptions = {}) {
|
|
36
38
|
for (let i = 0; i < this.mongoURI.length; i++) {
|
|
37
39
|
const uri = this.mongoURI[i].replaceAll("readonly:", '');
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
useNewUrlParser: true,
|
|
42
|
-
useUnifiedTopology: true,
|
|
43
|
-
};
|
|
41
|
+
|
|
42
|
+
|
|
44
43
|
|
|
45
44
|
const con = mongoose.createConnection(uri, connectionOptions);
|
|
46
45
|
|
|
@@ -92,7 +91,9 @@ class MongoModel {
|
|
|
92
91
|
}
|
|
93
92
|
|
|
94
93
|
static currentIndex = 0
|
|
95
|
-
|
|
94
|
+
get types() {
|
|
95
|
+
return mongoose.Schema.Types
|
|
96
|
+
}
|
|
96
97
|
async findInAllDatabase(filter, chain = {}) {
|
|
97
98
|
const dynamicComputationPromises = [];
|
|
98
99
|
this.model.forEach((modelRef) => {
|
|
@@ -125,7 +126,7 @@ class MongoModel {
|
|
|
125
126
|
async UpdateOneInAllDatabase(filter, update) {
|
|
126
127
|
const dynamicComputationPromises = [];
|
|
127
128
|
this.model.forEach((modelRef) => {
|
|
128
|
-
dynamicComputationPromises.push({ fn: modelRef.findOneAndUpdate.bind(modelRef), params: [filter, update, {
|
|
129
|
+
dynamicComputationPromises.push({ fn: modelRef.findOneAndUpdate.bind(modelRef), params: [filter, update, { returnDocument: 'after' }], chain: {} });
|
|
129
130
|
});
|
|
130
131
|
return await this.runLargeComputations(dynamicComputationPromises);
|
|
131
132
|
}
|
|
@@ -133,7 +134,7 @@ class MongoModel {
|
|
|
133
134
|
async UpdateByIdInAllDatabase(id, update) {
|
|
134
135
|
const dynamicComputationPromises = [];
|
|
135
136
|
this.model.forEach((modelRef) => {
|
|
136
|
-
dynamicComputationPromises.push({ fn: modelRef.findByIdAndUpdate.bind(modelRef), params: [id, update, {
|
|
137
|
+
dynamicComputationPromises.push({ fn: modelRef.findByIdAndUpdate.bind(modelRef), params: [id, update, { returnDocument: 'after' }], chain: {} });
|
|
137
138
|
});
|
|
138
139
|
return await this.runLargeComputations(dynamicComputationPromises);
|
|
139
140
|
}
|
|
@@ -385,18 +386,18 @@ class MongoModel {
|
|
|
385
386
|
|
|
386
387
|
async findByIdAndUpdate(dbIndex, id, update) {
|
|
387
388
|
var currentModel = this.model[dbIndex]
|
|
388
|
-
return currentModel.findByIdAndUpdate(id, update, {
|
|
389
|
+
return currentModel.findByIdAndUpdate(id, update, { returnDocument: 'after' });
|
|
389
390
|
}
|
|
390
391
|
|
|
391
392
|
async findByIdAndDelete(dbIndex, id) {
|
|
392
393
|
var currentModel = this.model[dbIndex]
|
|
393
394
|
// Changed from findByIdAndRemove to findByIdAndDelete (Mongoose 8 removed findByIdAndRemove)
|
|
394
|
-
return currentModel.findByIdAndDelete(id, {
|
|
395
|
+
return currentModel.findByIdAndDelete(id, { returnDocument: 'after' });
|
|
395
396
|
}
|
|
396
397
|
|
|
397
398
|
async findOneAndUpdate(dbIndex, filter, update) {
|
|
398
399
|
var currentModel = this.model[dbIndex]
|
|
399
|
-
return currentModel.findOneAndUpdate(filter, update, {
|
|
400
|
+
return currentModel.findOneAndUpdate(filter, update, { returnDocument: 'after' });
|
|
400
401
|
}
|
|
401
402
|
|
|
402
403
|
async aggregate(dbIndex, filter, update) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoplusplus",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "load balancing of read and write operations across multiple MongoDB servers ",
|
|
5
5
|
"main": "mongoplus.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -60,4 +60,4 @@
|
|
|
60
60
|
},
|
|
61
61
|
"./package.json": "./package.json"
|
|
62
62
|
}
|
|
63
|
-
}
|
|
63
|
+
}
|
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}`,
|