@tomsd/mongodbclient 2.7.0 → 2.7.3
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/dist/cjs/mongodbclient.d.ts +3 -3
- package/dist/cjs/mongodbclient.js +19 -25
- package/dist/esm/mongodbclient.d.ts +3 -3
- package/dist/esm/mongodbclient.js +19 -25
- package/package.json +1 -1
- package/test/test.ts +5 -0
|
@@ -22,8 +22,8 @@ export declare class MClient {
|
|
|
22
22
|
get uri(): string;
|
|
23
23
|
get db(): string;
|
|
24
24
|
get collection(): string;
|
|
25
|
-
connect(): Promise<
|
|
26
|
-
protected getConnected(): Promise<
|
|
25
|
+
connect(): Promise<any>;
|
|
26
|
+
protected getConnected(): Promise<any>;
|
|
27
27
|
upsert(pobj: any): Promise<unknown>;
|
|
28
28
|
read(condition?: any, opt?: any): Promise<unknown>;
|
|
29
29
|
distinct(key: string, condition?: any): Promise<unknown>;
|
|
@@ -31,7 +31,7 @@ export declare class MClient {
|
|
|
31
31
|
stats(): Promise<unknown>;
|
|
32
32
|
count(condition?: any): Promise<number>;
|
|
33
33
|
insertMany(items: any[]): Promise<unknown>;
|
|
34
|
-
dbStats(): Promise<
|
|
34
|
+
dbStats(): Promise<any>;
|
|
35
35
|
getCollections(): Promise<any>;
|
|
36
36
|
}
|
|
37
37
|
export default MClient;
|
|
@@ -55,17 +55,14 @@ class MClient {
|
|
|
55
55
|
return this.getConnected();
|
|
56
56
|
}
|
|
57
57
|
getConnected() {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
.then(
|
|
63
|
-
const db = client.db(
|
|
64
|
-
const collection = db.collection(
|
|
65
|
-
|
|
66
|
-
})
|
|
67
|
-
.catch(function (e) {
|
|
68
|
-
reject(e);
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const client = new MongoClient(this.m_uri, { useUnifiedTopology: true });
|
|
60
|
+
return client
|
|
61
|
+
.connect()
|
|
62
|
+
.then((client) => {
|
|
63
|
+
const db = client.db(this.m_db);
|
|
64
|
+
const collection = db.collection(this.m_collection);
|
|
65
|
+
return new MongoConnection(client, db, collection);
|
|
69
66
|
});
|
|
70
67
|
});
|
|
71
68
|
}
|
|
@@ -191,20 +188,17 @@ class MClient {
|
|
|
191
188
|
});
|
|
192
189
|
}
|
|
193
190
|
dbStats() {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
.
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
reject(e);
|
|
206
|
-
});
|
|
207
|
-
}, reject);
|
|
191
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
const connection = yield this.getConnected();
|
|
193
|
+
try {
|
|
194
|
+
return yield connection.db.stats();
|
|
195
|
+
}
|
|
196
|
+
catch (e) {
|
|
197
|
+
throw e;
|
|
198
|
+
}
|
|
199
|
+
finally {
|
|
200
|
+
connection.client.close();
|
|
201
|
+
}
|
|
208
202
|
});
|
|
209
203
|
}
|
|
210
204
|
getCollections() {
|
|
@@ -22,8 +22,8 @@ export declare class MClient {
|
|
|
22
22
|
get uri(): string;
|
|
23
23
|
get db(): string;
|
|
24
24
|
get collection(): string;
|
|
25
|
-
connect(): Promise<
|
|
26
|
-
protected getConnected(): Promise<
|
|
25
|
+
connect(): Promise<any>;
|
|
26
|
+
protected getConnected(): Promise<any>;
|
|
27
27
|
upsert(pobj: any): Promise<unknown>;
|
|
28
28
|
read(condition?: any, opt?: any): Promise<unknown>;
|
|
29
29
|
distinct(key: string, condition?: any): Promise<unknown>;
|
|
@@ -31,7 +31,7 @@ export declare class MClient {
|
|
|
31
31
|
stats(): Promise<unknown>;
|
|
32
32
|
count(condition?: any): Promise<number>;
|
|
33
33
|
insertMany(items: any[]): Promise<unknown>;
|
|
34
|
-
dbStats(): Promise<
|
|
34
|
+
dbStats(): Promise<any>;
|
|
35
35
|
getCollections(): Promise<any>;
|
|
36
36
|
}
|
|
37
37
|
export default MClient;
|
|
@@ -51,17 +51,14 @@ export class MClient {
|
|
|
51
51
|
return this.getConnected();
|
|
52
52
|
}
|
|
53
53
|
getConnected() {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
.then(
|
|
59
|
-
const db = client.db(
|
|
60
|
-
const collection = db.collection(
|
|
61
|
-
|
|
62
|
-
})
|
|
63
|
-
.catch(function (e) {
|
|
64
|
-
reject(e);
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const client = new MongoClient(this.m_uri, { useUnifiedTopology: true });
|
|
56
|
+
return client
|
|
57
|
+
.connect()
|
|
58
|
+
.then((client) => {
|
|
59
|
+
const db = client.db(this.m_db);
|
|
60
|
+
const collection = db.collection(this.m_collection);
|
|
61
|
+
return new MongoConnection(client, db, collection);
|
|
65
62
|
});
|
|
66
63
|
});
|
|
67
64
|
}
|
|
@@ -187,20 +184,17 @@ export class MClient {
|
|
|
187
184
|
});
|
|
188
185
|
}
|
|
189
186
|
dbStats() {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
.
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
reject(e);
|
|
202
|
-
});
|
|
203
|
-
}, reject);
|
|
187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
const connection = yield this.getConnected();
|
|
189
|
+
try {
|
|
190
|
+
return yield connection.db.stats();
|
|
191
|
+
}
|
|
192
|
+
catch (e) {
|
|
193
|
+
throw e;
|
|
194
|
+
}
|
|
195
|
+
finally {
|
|
196
|
+
connection.client.close();
|
|
197
|
+
}
|
|
204
198
|
});
|
|
205
199
|
}
|
|
206
200
|
getCollections() {
|
package/package.json
CHANGED
package/test/test.ts
CHANGED
|
@@ -47,6 +47,11 @@ describe("MClient", () => {
|
|
|
47
47
|
assert.equal(names.length, 4);
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
+
it("dbStats()", async () => {
|
|
51
|
+
const { storageSize } = (await mdbc.dbStats()) as { storageSize: number };
|
|
52
|
+
assert(storageSize > 0);
|
|
53
|
+
});
|
|
54
|
+
|
|
50
55
|
it("stats()", async () => {
|
|
51
56
|
const { storageSize } = (await mdbc.stats()) as { storageSize: number };
|
|
52
57
|
assert(storageSize > 0);
|