@pi-r/mongodb 0.6.0 → 0.6.1
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 +24 -27
- package/package.json +4 -4
package/client/index.js
CHANGED
|
@@ -318,15 +318,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
318
318
|
const getCollection = (target) => getInstance(target).collection(table, client?.collection);
|
|
319
319
|
const runCommand = async (target, document) => getInstance(target).command(document, client?.command);
|
|
320
320
|
const credential = mongoCredential || onceCredential || getCacheObject(item);
|
|
321
|
-
const
|
|
322
|
-
const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
|
|
321
|
+
const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
|
|
323
322
|
const coercing = this.hasCoerce("mongodb" /* STRINGS.MODULE_NAME */, 'options', credential.uuidKey);
|
|
324
323
|
const targetObject = typeof checkObject === 'string' ? coercing && (0, types_1.asFunction)(checkObject) : checkObject;
|
|
325
324
|
if (typeof streamRow === 'string') {
|
|
326
325
|
streamRow = coercing && (0, types_1.asFunction)(streamRow);
|
|
327
326
|
}
|
|
328
327
|
let queryString = '', rows, pipeline;
|
|
329
|
-
if (
|
|
328
|
+
if (caching && ignoreCache !== true && (!targetObject || typeof cacheObjectKey === 'string') && !streamRow) {
|
|
330
329
|
queryString = (name || '') + '_' + table + '_' + limit + Db.asString(sort, true) + Db.asString(client, true) + (targetObject ? targetObject.toString() + cacheObjectKey : '');
|
|
331
330
|
}
|
|
332
331
|
if (aggregate) {
|
|
@@ -383,9 +382,26 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
383
382
|
await Promise.all((!Array.isArray(command) ? [command] : command).map(async (cmd) => runCommand(instance, cmd)))
|
|
384
383
|
.then(items => items.forEach(output => this.addLog(this.statusType.INFO, output, "mongodb" /* STRINGS.MODULE_NAME */, 'runCommand')));
|
|
385
384
|
}
|
|
385
|
+
const collection = getCollection(instance);
|
|
386
|
+
if (update && coercing) {
|
|
387
|
+
(0, types_1.coerceObject)(update);
|
|
388
|
+
}
|
|
389
|
+
if (Array.isArray(update)) {
|
|
390
|
+
commandType = this.commandType.INSERT;
|
|
391
|
+
const insertOptions = item.execute?.insert;
|
|
392
|
+
if (insertOptions && coercing) {
|
|
393
|
+
(0, types_1.coerceObject)(insertOptions);
|
|
394
|
+
}
|
|
395
|
+
if (update.length === 1) {
|
|
396
|
+
await collection.insertOne(update[0], insertOptions);
|
|
397
|
+
}
|
|
398
|
+
else if (update.length > 1) {
|
|
399
|
+
await collection.insertMany(update, insertOptions);
|
|
400
|
+
}
|
|
401
|
+
update = undefined;
|
|
402
|
+
}
|
|
386
403
|
let cursor;
|
|
387
404
|
if (pipeline || query) {
|
|
388
|
-
const collection = getCollection(instance);
|
|
389
405
|
if (pipeline) {
|
|
390
406
|
const aggregateOptions = (0, types_1.isPlainObject)(aggregate) ? aggregate.options : undefined;
|
|
391
407
|
if (coercing) {
|
|
@@ -404,31 +420,12 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
404
420
|
}
|
|
405
421
|
else {
|
|
406
422
|
const [filter, operation] = getFilterValue(query, coercing);
|
|
407
|
-
|
|
408
|
-
(0, types_1.coerceObject)(update);
|
|
409
|
-
}
|
|
410
|
-
if ((0, types_1.isArray)(update)) {
|
|
411
|
-
commandType = this.commandType.INSERT;
|
|
412
|
-
const insertOptions = item.execute?.insert;
|
|
413
|
-
if (insertOptions && coercing) {
|
|
414
|
-
(0, types_1.coerceObject)(insertOptions);
|
|
415
|
-
}
|
|
416
|
-
if (update.length === 1) {
|
|
417
|
-
await collection.insertOne(update[0], insertOptions);
|
|
418
|
-
}
|
|
419
|
-
else {
|
|
420
|
-
await collection.insertMany(update, insertOptions);
|
|
421
|
-
}
|
|
422
|
-
update = undefined;
|
|
423
|
-
}
|
|
424
|
-
else if (item.updateType === 1) {
|
|
425
|
-
update = undefined;
|
|
426
|
-
}
|
|
423
|
+
const updateType = item.updateType;
|
|
427
424
|
if (limit === 1) {
|
|
428
425
|
let document;
|
|
429
426
|
if (update) {
|
|
430
427
|
commandType = this.commandType.UPDATE;
|
|
431
|
-
document = await collection[
|
|
428
|
+
document = await collection[updateType === 2 ? 'findOneAndReplace' : updateType === 3 ? 'findOneAndDelete' : 'findOneAndUpdate'](filter, update, operation);
|
|
432
429
|
}
|
|
433
430
|
else {
|
|
434
431
|
commandType = this.commandType.SELECT;
|
|
@@ -437,7 +434,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
437
434
|
rows = document ? [document] : [];
|
|
438
435
|
}
|
|
439
436
|
else {
|
|
440
|
-
if (update) {
|
|
437
|
+
if (update && updateType === 1) {
|
|
441
438
|
commandType = this.commandType.UPDATE;
|
|
442
439
|
const updateOptions = item.execute?.update;
|
|
443
440
|
if (updateOptions && coercing) {
|
|
@@ -450,7 +447,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
450
447
|
}
|
|
451
448
|
}
|
|
452
449
|
else if (!aggregate) {
|
|
453
|
-
cursor =
|
|
450
|
+
cursor = collection.find();
|
|
454
451
|
}
|
|
455
452
|
if (cursor) {
|
|
456
453
|
commandType = this.commandType.SELECT;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/mongodb",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "MongoDB client driver for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"types": "client/index.d.ts",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@e-mc/db": "^0.8.
|
|
25
|
-
"@e-mc/request": "^0.8.
|
|
26
|
-
"@e-mc/types": "^0.8.
|
|
24
|
+
"@e-mc/db": "^0.8.1",
|
|
25
|
+
"@e-mc/request": "^0.8.1",
|
|
26
|
+
"@e-mc/types": "^0.8.1",
|
|
27
27
|
"mongodb": "^6.3.0"
|
|
28
28
|
}
|
|
29
29
|
}
|