@pi-r/mongodb 0.3.6 → 0.3.7
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/client/index.js +7 -7
- package/package.json +1 -1
package/client/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DB_SOURCE_TYPE = exports.DB_SOURCE_CLIENT = exports.getSortValue = exports.getFilterValue = exports.checkTimeout = exports.executeBatchQuery = exports.executeQuery = exports.setCredential = void 0;
|
|
4
4
|
const path = require("path");
|
|
5
|
+
const mongodb = require("mongodb");
|
|
5
6
|
const types_1 = require("@e-mc/types");
|
|
6
7
|
const util_1 = require("@e-mc/db/util");
|
|
7
8
|
const Db = require("@e-mc/db");
|
|
@@ -25,7 +26,7 @@ class MongoDBPool extends DbPool {
|
|
|
25
26
|
return this.client.close(force);
|
|
26
27
|
}
|
|
27
28
|
isEmpty() {
|
|
28
|
-
var _a;
|
|
29
|
+
var _a, _b;
|
|
29
30
|
if (this.closed) {
|
|
30
31
|
return true;
|
|
31
32
|
}
|
|
@@ -37,7 +38,7 @@ class MongoDBPool extends DbPool {
|
|
|
37
38
|
return (0, util_1.checkEmpty)(topology[name]);
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
|
-
return (0, util_1.checkEmpty)((_a = topology.s) === null || _a === void 0 ? void 0 : _a.sessions);
|
|
41
|
+
return (0, util_1.checkEmpty)((_a = topology.s) === null || _a === void 0 ? void 0 : _a.sessions) && (0, util_1.checkEmpty)((_b = topology.s) === null || _b === void 0 ? void 0 : _b.servers);
|
|
41
42
|
}
|
|
42
43
|
return false;
|
|
43
44
|
}
|
|
@@ -346,8 +347,7 @@ function setCredential(item) {
|
|
|
346
347
|
}
|
|
347
348
|
}
|
|
348
349
|
}
|
|
349
|
-
|
|
350
|
-
new MongoDBPool(new db.MongoClient(item.uri, options), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
|
|
350
|
+
new MongoDBPool(new mongodb.MongoClient(item.uri, options), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
|
|
351
351
|
}
|
|
352
352
|
else {
|
|
353
353
|
pool.add(item);
|
|
@@ -368,7 +368,6 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
368
368
|
if (length === 0) {
|
|
369
369
|
return [];
|
|
370
370
|
}
|
|
371
|
-
const db = require("mongodb");
|
|
372
371
|
let parallel, checkObject, connectOnce, errorQuery, sessionKey, outCacheMiss;
|
|
373
372
|
if ((0, types_1.isPlainObject)(options)) {
|
|
374
373
|
({ parallel, checkObject, connectOnce, errorQuery, sessionKey, outCacheMiss } = options);
|
|
@@ -416,7 +415,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
416
415
|
credential.options.maxPoolSize = size;
|
|
417
416
|
}
|
|
418
417
|
}
|
|
419
|
-
clients.push(client = await new
|
|
418
|
+
clients.push(client = await new mongodb.MongoClient(credential.uri, credential.options).connect());
|
|
420
419
|
}
|
|
421
420
|
if (connectOnce) {
|
|
422
421
|
mongoClient = client;
|
|
@@ -465,7 +464,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
465
464
|
pipeline = Array.isArray(aggregate) ? aggregate : aggregate.pipeline;
|
|
466
465
|
}
|
|
467
466
|
if (id && (!query || limit === 1) && !pipeline) {
|
|
468
|
-
query = { '_id': new
|
|
467
|
+
query = { '_id': new mongodb.ObjectId(id) };
|
|
469
468
|
limit = 1;
|
|
470
469
|
}
|
|
471
470
|
if (queryString) {
|
|
@@ -570,6 +569,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
570
569
|
if (updateOptions && coercing) {
|
|
571
570
|
(0, types_1.coerceObject)(updateOptions);
|
|
572
571
|
}
|
|
572
|
+
await collection.updateMany(filter, update, updateOptions);
|
|
573
573
|
}
|
|
574
574
|
cursor = collection.find(filter, command);
|
|
575
575
|
}
|