@tomsd/mongodbclient 2.3.0 → 2.6.0
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.
|
@@ -25,11 +25,11 @@ export declare class MClient {
|
|
|
25
25
|
connect(): Promise<MongoConnection>;
|
|
26
26
|
protected getConnected(): Promise<MongoConnection>;
|
|
27
27
|
upsert(pobj: any): Promise<unknown>;
|
|
28
|
-
read(condition
|
|
29
|
-
distinct(key: string, condition
|
|
28
|
+
read(condition?: any, opt?: any): Promise<unknown>;
|
|
29
|
+
distinct(key: string, condition?: any): Promise<unknown>;
|
|
30
30
|
remove(condition: any): Promise<unknown>;
|
|
31
31
|
stats(): Promise<unknown>;
|
|
32
|
-
count(condition
|
|
32
|
+
count(condition?: any): Promise<number>;
|
|
33
33
|
insertMany(items: any[]): Promise<unknown>;
|
|
34
34
|
dbStats(): Promise<unknown>;
|
|
35
35
|
getCollections(): Promise<any[]>;
|
|
@@ -78,7 +78,7 @@ class MClient {
|
|
|
78
78
|
}, reject);
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
|
-
read(condition, opt) {
|
|
81
|
+
read(condition = {}, opt) {
|
|
82
82
|
const that = this;
|
|
83
83
|
return new Promise(function (resolve, reject) {
|
|
84
84
|
that.getConnected()
|
|
@@ -96,7 +96,7 @@ class MClient {
|
|
|
96
96
|
});
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
|
-
distinct(key, condition) {
|
|
99
|
+
distinct(key, condition = {}) {
|
|
100
100
|
const that = this;
|
|
101
101
|
return new Promise(function (resolve, reject) {
|
|
102
102
|
that.getConnected()
|
|
@@ -147,7 +147,7 @@ class MClient {
|
|
|
147
147
|
}, reject);
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
|
-
count(condition) {
|
|
150
|
+
count(condition = {}) {
|
|
151
151
|
const that = this;
|
|
152
152
|
return new Promise(function (resolve, reject) {
|
|
153
153
|
that.getConnected()
|
|
@@ -25,11 +25,11 @@ export declare class MClient {
|
|
|
25
25
|
connect(): Promise<MongoConnection>;
|
|
26
26
|
protected getConnected(): Promise<MongoConnection>;
|
|
27
27
|
upsert(pobj: any): Promise<unknown>;
|
|
28
|
-
read(condition
|
|
29
|
-
distinct(key: string, condition
|
|
28
|
+
read(condition?: any, opt?: any): Promise<unknown>;
|
|
29
|
+
distinct(key: string, condition?: any): Promise<unknown>;
|
|
30
30
|
remove(condition: any): Promise<unknown>;
|
|
31
31
|
stats(): Promise<unknown>;
|
|
32
|
-
count(condition
|
|
32
|
+
count(condition?: any): Promise<number>;
|
|
33
33
|
insertMany(items: any[]): Promise<unknown>;
|
|
34
34
|
dbStats(): Promise<unknown>;
|
|
35
35
|
getCollections(): Promise<any[]>;
|
|
@@ -74,7 +74,7 @@ export class MClient {
|
|
|
74
74
|
}, reject);
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
|
-
read(condition, opt) {
|
|
77
|
+
read(condition = {}, opt) {
|
|
78
78
|
const that = this;
|
|
79
79
|
return new Promise(function (resolve, reject) {
|
|
80
80
|
that.getConnected()
|
|
@@ -92,7 +92,7 @@ export class MClient {
|
|
|
92
92
|
});
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
|
-
distinct(key, condition) {
|
|
95
|
+
distinct(key, condition = {}) {
|
|
96
96
|
const that = this;
|
|
97
97
|
return new Promise(function (resolve, reject) {
|
|
98
98
|
that.getConnected()
|
|
@@ -143,7 +143,7 @@ export class MClient {
|
|
|
143
143
|
}, reject);
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
|
-
count(condition) {
|
|
146
|
+
count(condition = {}) {
|
|
147
147
|
const that = this;
|
|
148
148
|
return new Promise(function (resolve, reject) {
|
|
149
149
|
that.getConnected()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomsd/mongodbclient",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/cjs/mongodbclient.js",
|
|
6
6
|
"module": "dist/esm/mongodbclient.js",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"@types/mongodb": "^3.5.31",
|
|
25
25
|
"@types/node": "^14.14.5",
|
|
26
26
|
"@types/uuid": "^8.3.4",
|
|
27
|
+
"dotenv": "^16.0.1",
|
|
27
28
|
"mocha": "^7.0.1",
|
|
28
29
|
"ts-node": "^10.8.1",
|
|
29
30
|
"typescript": "^4.0.5"
|
package/test/test.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import dotenv from "dotenv";
|
|
3
|
+
dotenv.config();
|
|
4
|
+
|
|
1
5
|
import {describe, it } from "mocha";
|
|
2
6
|
import { MClient } from "../src/mongodbclient";
|
|
3
7
|
import { strict as assert } from "assert";
|
|
4
8
|
import { v4 as uuidv4 } from "uuid";
|
|
5
9
|
|
|
6
|
-
const mongouri =
|
|
10
|
+
const mongouri = process.env.MONGODB_URI as string;
|
|
7
11
|
const dbName = uuidv4();
|
|
8
12
|
const collName = uuidv4();
|
|
9
13
|
|
|
@@ -28,18 +32,18 @@ describe("MClient", () => {
|
|
|
28
32
|
});
|
|
29
33
|
|
|
30
34
|
it("read()", async () => {
|
|
31
|
-
const docs = (await mdbc.read(
|
|
35
|
+
const docs = (await mdbc.read()) as any[];
|
|
32
36
|
assert.equal(docs.length, items.length);
|
|
33
37
|
});
|
|
34
38
|
|
|
35
39
|
it("upsert()", async () => {
|
|
36
|
-
const docs = (await mdbc.read(
|
|
40
|
+
const docs = (await mdbc.read()) as any[];
|
|
37
41
|
const { modifiedCount } = (await mdbc.upsert({ _id: docs[0]._id, name: "david" })) as { modifiedCount: number };
|
|
38
42
|
assert.equal(modifiedCount, 1);
|
|
39
43
|
});
|
|
40
44
|
|
|
41
45
|
it("distinct()", async () => {
|
|
42
|
-
const names = (await mdbc.distinct("name"
|
|
46
|
+
const names = (await mdbc.distinct("name")) as string[];
|
|
43
47
|
assert.equal(names.length, 4);
|
|
44
48
|
});
|
|
45
49
|
|