@tomsd/mongodbclient 3.0.14 → 4.0.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/README.md CHANGED
@@ -3,12 +3,17 @@
3
3
  It's a handy mongodb client for easy-use.
4
4
  See [mongodbclient.netlify.app](https://mongodbclient.netlify.app/) for details.
5
5
 
6
- ![npm](https://img.shields.io/npm/v/@tomsd/mongodbclient)
7
- ![NPM](https://img.shields.io/npm/l/@tomsd/mongodbclient)
8
- ![npms.io (quality)](https://img.shields.io/npms-io/quality-score/@tomsd/mongodbclient)
9
- ![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/npm/@tomsd/mongodbclient)
10
- ![Maintenance](https://img.shields.io/maintenance/yes/2024)
11
- ![depends on mongodb@4](https://img.shields.io/badge/depends%20on-mongodb@4-informational)
6
+ ![npm](https://img.shields.io/npm/v/@tomsd/mongodbclient?style=for-the-badge&logo=npm)
7
+ ![NPM](https://img.shields.io/npm/l/@tomsd/mongodbclient?style=for-the-badge&logo=npm)
8
+ ![release date](https://img.shields.io/github/release-date/tomsdoo/mongodbclient?style=for-the-badge&logo=npm)
9
+ ![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/npm/@tomsd/mongodbclient?style=for-the-badge&logo=npm)
10
+
11
+ ![ci](https://img.shields.io/github/actions/workflow/status/tomsdoo/mongodbclient/ci.yml?style=social&logo=github)
12
+ ![checks](https://img.shields.io/github/check-runs/tomsdoo/mongodbclient/main?style=social&logo=github)
13
+ ![top language](https://img.shields.io/github/languages/top/tomsdoo/mongodbclient?style=social&logo=typescript)
14
+ ![Maintenance](https://img.shields.io/maintenance/yes/2024?style=social&logo=github)
15
+ ![depends on mongodb@6](https://img.shields.io/badge/mongodb-mongodb@6-informational?style=social&logo=mongodb)
16
+ ![depends on node greater or equal 18](https://img.shields.io/badge/node.js-%3E%3D%2018-lightyellow?style=social&logo=nodedotjs)
12
17
 
13
18
  ## Installation
14
19
  ``` sh
@@ -49,9 +54,6 @@ const items = [
49
54
  const names = await mdbc.distinct("name");
50
55
  console.log(`distinct names: ${names.length}`); // 4
51
56
 
52
- const { storageSize } = await mdbc.stats();
53
- console.log(`storageSize: ${storageSize}`);
54
-
55
57
  const itemLength = await mdbc.count();
56
58
  console.log(`count: ${itemLength}`); // 4
57
59
 
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -24,8 +25,8 @@ __export(mongodbclient_exports, {
24
25
  default: () => mongodbclient_default
25
26
  });
26
27
  module.exports = __toCommonJS(mongodbclient_exports);
28
+ var import_mongodb = require("mongodb");
27
29
  var import_uuid = require("uuid");
28
- var MongoClient = require("mongodb").MongoClient;
29
30
  var MongoConnection = class {
30
31
  _client;
31
32
  _db;
@@ -67,8 +68,10 @@ var MClient = class {
67
68
  return await this.getConnected();
68
69
  }
69
70
  async getConnected() {
70
- const client = new MongoClient(this.m_uri, { useUnifiedTopology: true });
71
- return client.connect().then((client2) => {
71
+ const client = new import_mongodb.MongoClient(this.m_uri, {
72
+ serverApi: import_mongodb.ServerApiVersion.v1
73
+ });
74
+ return await client.connect().then((client2) => {
72
75
  const db = client2.db(this.m_db);
73
76
  const collection = db.collection(this.m_collection);
74
77
  return new MongoConnection(client2, db, collection);
@@ -87,15 +90,18 @@ var MClient = class {
87
90
  { upsert: true, writeConcern: { w: 1 } }
88
91
  );
89
92
  } finally {
90
- connection.client.close();
93
+ await connection.client.close();
91
94
  }
92
95
  }
93
96
  async read(condition = {}, opt) {
94
97
  const connection = await this.getConnected();
95
98
  try {
96
- return await connection.collection.find(condition, opt).toArray();
99
+ return await connection.collection.find(
100
+ condition,
101
+ opt
102
+ ).toArray();
97
103
  } finally {
98
- connection.client.close();
104
+ await connection.client.close();
99
105
  }
100
106
  }
101
107
  async distinct(key, condition = {}) {
@@ -103,40 +109,57 @@ var MClient = class {
103
109
  try {
104
110
  return await connection.collection.distinct(
105
111
  key,
106
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
107
112
  condition
108
113
  );
109
114
  } finally {
110
- connection.client.close();
115
+ await connection.client.close();
111
116
  }
112
117
  }
113
118
  async remove(condition) {
114
119
  const connection = await this.getConnected();
115
120
  try {
116
- return await connection.collection.deleteMany(condition, {
117
- writeConcern: { w: 1 }
118
- });
121
+ return await connection.collection.deleteMany(
122
+ condition,
123
+ {
124
+ writeConcern: { w: 1 }
125
+ }
126
+ );
119
127
  } finally {
120
- connection.client.close();
128
+ await connection.client.close();
121
129
  }
122
130
  }
123
131
  async stats() {
124
132
  const connection = await this.getConnected();
125
133
  try {
126
- return await connection.collection.stats();
134
+ const [collStats] = await connection.collection.aggregate([
135
+ {
136
+ $collStats: {
137
+ latencyStats: {
138
+ histograms: true
139
+ },
140
+ count: {},
141
+ queryExecStats: {},
142
+ storageStats: {
143
+ scale: 1
144
+ }
145
+ }
146
+ }
147
+ ]).toArray();
148
+ return collStats;
149
+ } catch (_) {
150
+ return null;
127
151
  } finally {
128
- connection.client.close();
152
+ await connection.client.close();
129
153
  }
130
154
  }
131
155
  async count(condition = {}) {
132
156
  const connection = await this.getConnected();
133
157
  try {
134
158
  return await connection.collection.countDocuments(
135
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
136
159
  condition
137
160
  );
138
161
  } finally {
139
- connection.client.close();
162
+ await connection.client.close();
140
163
  }
141
164
  }
142
165
  async insertMany(items) {
@@ -146,11 +169,15 @@ var MClient = class {
146
169
  ...item
147
170
  }));
148
171
  try {
149
- return await connection.collection.insertMany(savingItems, {
150
- writeConcern: { w: 1 }
151
- });
172
+ return await connection.collection.insertMany(
173
+ // biome-ignore lint: Array<T>
174
+ savingItems,
175
+ {
176
+ writeConcern: { w: 1 }
177
+ }
178
+ );
152
179
  } finally {
153
- connection.client.close();
180
+ await connection.client.close();
154
181
  }
155
182
  }
156
183
  async dbStats() {
@@ -158,7 +185,7 @@ var MClient = class {
158
185
  try {
159
186
  return await connection.db.stats();
160
187
  } finally {
161
- connection.client.close();
188
+ await connection.client.close();
162
189
  }
163
190
  }
164
191
  async getCollections() {
@@ -166,7 +193,7 @@ var MClient = class {
166
193
  try {
167
194
  return await connection.db.collections();
168
195
  } finally {
169
- connection.client.close();
196
+ await connection.client.close();
170
197
  }
171
198
  }
172
199
  };
@@ -176,8 +203,3 @@ var mongodbclient_default = MClient;
176
203
  MClient,
177
204
  MongoConnection
178
205
  });
179
- /*!
180
- * @license mongodbclient
181
- * (c) 2020 tom
182
- * License: MIT
183
- */
@@ -0,0 +1,33 @@
1
+ import { MongoClient, Db, Collection, UpdateResult, WithId, Document, DeleteResult, InsertManyResult } from 'mongodb';
2
+
3
+ declare class MongoConnection {
4
+ private readonly _client;
5
+ private readonly _db;
6
+ private readonly _collection;
7
+ constructor(client: MongoClient, db: Db, collection: Collection);
8
+ get client(): MongoClient;
9
+ get db(): Db;
10
+ get collection(): Collection;
11
+ }
12
+ declare class MClient {
13
+ private readonly m_uri;
14
+ private readonly m_db;
15
+ private readonly m_collection;
16
+ constructor(uri: string, db: string, collection: string);
17
+ get uri(): string;
18
+ get db(): string;
19
+ get collection(): string;
20
+ connect(): Promise<MongoConnection>;
21
+ protected getConnected(): Promise<MongoConnection>;
22
+ upsert(pobj: any): Promise<UpdateResult>;
23
+ read(condition?: any, opt?: any): Promise<WithId<Document>[]>;
24
+ distinct(key: string, condition?: any): Promise<any[]>;
25
+ remove(condition: any): Promise<DeleteResult>;
26
+ stats(): Promise<Document | null>;
27
+ count(condition?: any): Promise<number>;
28
+ insertMany(items: any[]): Promise<InsertManyResult<Document>>;
29
+ dbStats(): Promise<Document>;
30
+ getCollections(): Promise<Collection[]>;
31
+ }
32
+
33
+ export { MClient, MongoConnection, MClient as default };
@@ -1,20 +1,15 @@
1
- /*!
2
- * @license mongodbclient
3
- * (c) 2020 tom
4
- * License: MIT
5
- */
6
- import type { Db, Collection, CollStats, DeleteResult, Document, InsertManyResult, UpdateResult, WithId } from "mongodb";
7
- declare const MongoClient: any;
8
- export declare class MongoConnection {
1
+ import { MongoClient, Db, Collection, UpdateResult, WithId, Document, DeleteResult, InsertManyResult } from 'mongodb';
2
+
3
+ declare class MongoConnection {
9
4
  private readonly _client;
10
5
  private readonly _db;
11
6
  private readonly _collection;
12
- constructor(client: typeof MongoClient, db: Db, collection: Collection);
13
- get client(): typeof MongoClient;
7
+ constructor(client: MongoClient, db: Db, collection: Collection);
8
+ get client(): MongoClient;
14
9
  get db(): Db;
15
10
  get collection(): Collection;
16
11
  }
17
- export declare class MClient {
12
+ declare class MClient {
18
13
  private readonly m_uri;
19
14
  private readonly m_db;
20
15
  private readonly m_collection;
@@ -25,13 +20,14 @@ export declare class MClient {
25
20
  connect(): Promise<MongoConnection>;
26
21
  protected getConnected(): Promise<MongoConnection>;
27
22
  upsert(pobj: any): Promise<UpdateResult>;
28
- read(condition?: any, opt?: any): Promise<Array<WithId<Document>>>;
23
+ read(condition?: any, opt?: any): Promise<WithId<Document>[]>;
29
24
  distinct(key: string, condition?: any): Promise<any[]>;
30
25
  remove(condition: any): Promise<DeleteResult>;
31
- stats(): Promise<CollStats>;
26
+ stats(): Promise<Document | null>;
32
27
  count(condition?: any): Promise<number>;
33
28
  insertMany(items: any[]): Promise<InsertManyResult<Document>>;
34
29
  dbStats(): Promise<Document>;
35
30
  getCollections(): Promise<Collection[]>;
36
31
  }
37
- export default MClient;
32
+
33
+ export { MClient, MongoConnection, MClient as default };
@@ -1,14 +1,6 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined")
5
- return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
-
9
1
  // src/mongodbclient.ts
2
+ import { MongoClient, ServerApiVersion } from "mongodb";
10
3
  import { v4 as uuidv4 } from "uuid";
11
- var MongoClient = __require("mongodb").MongoClient;
12
4
  var MongoConnection = class {
13
5
  _client;
14
6
  _db;
@@ -50,8 +42,10 @@ var MClient = class {
50
42
  return await this.getConnected();
51
43
  }
52
44
  async getConnected() {
53
- const client = new MongoClient(this.m_uri, { useUnifiedTopology: true });
54
- return client.connect().then((client2) => {
45
+ const client = new MongoClient(this.m_uri, {
46
+ serverApi: ServerApiVersion.v1
47
+ });
48
+ return await client.connect().then((client2) => {
55
49
  const db = client2.db(this.m_db);
56
50
  const collection = db.collection(this.m_collection);
57
51
  return new MongoConnection(client2, db, collection);
@@ -70,15 +64,18 @@ var MClient = class {
70
64
  { upsert: true, writeConcern: { w: 1 } }
71
65
  );
72
66
  } finally {
73
- connection.client.close();
67
+ await connection.client.close();
74
68
  }
75
69
  }
76
70
  async read(condition = {}, opt) {
77
71
  const connection = await this.getConnected();
78
72
  try {
79
- return await connection.collection.find(condition, opt).toArray();
73
+ return await connection.collection.find(
74
+ condition,
75
+ opt
76
+ ).toArray();
80
77
  } finally {
81
- connection.client.close();
78
+ await connection.client.close();
82
79
  }
83
80
  }
84
81
  async distinct(key, condition = {}) {
@@ -86,40 +83,57 @@ var MClient = class {
86
83
  try {
87
84
  return await connection.collection.distinct(
88
85
  key,
89
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
90
86
  condition
91
87
  );
92
88
  } finally {
93
- connection.client.close();
89
+ await connection.client.close();
94
90
  }
95
91
  }
96
92
  async remove(condition) {
97
93
  const connection = await this.getConnected();
98
94
  try {
99
- return await connection.collection.deleteMany(condition, {
100
- writeConcern: { w: 1 }
101
- });
95
+ return await connection.collection.deleteMany(
96
+ condition,
97
+ {
98
+ writeConcern: { w: 1 }
99
+ }
100
+ );
102
101
  } finally {
103
- connection.client.close();
102
+ await connection.client.close();
104
103
  }
105
104
  }
106
105
  async stats() {
107
106
  const connection = await this.getConnected();
108
107
  try {
109
- return await connection.collection.stats();
108
+ const [collStats] = await connection.collection.aggregate([
109
+ {
110
+ $collStats: {
111
+ latencyStats: {
112
+ histograms: true
113
+ },
114
+ count: {},
115
+ queryExecStats: {},
116
+ storageStats: {
117
+ scale: 1
118
+ }
119
+ }
120
+ }
121
+ ]).toArray();
122
+ return collStats;
123
+ } catch (_) {
124
+ return null;
110
125
  } finally {
111
- connection.client.close();
126
+ await connection.client.close();
112
127
  }
113
128
  }
114
129
  async count(condition = {}) {
115
130
  const connection = await this.getConnected();
116
131
  try {
117
132
  return await connection.collection.countDocuments(
118
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
119
133
  condition
120
134
  );
121
135
  } finally {
122
- connection.client.close();
136
+ await connection.client.close();
123
137
  }
124
138
  }
125
139
  async insertMany(items) {
@@ -129,11 +143,15 @@ var MClient = class {
129
143
  ...item
130
144
  }));
131
145
  try {
132
- return await connection.collection.insertMany(savingItems, {
133
- writeConcern: { w: 1 }
134
- });
146
+ return await connection.collection.insertMany(
147
+ // biome-ignore lint: Array<T>
148
+ savingItems,
149
+ {
150
+ writeConcern: { w: 1 }
151
+ }
152
+ );
135
153
  } finally {
136
- connection.client.close();
154
+ await connection.client.close();
137
155
  }
138
156
  }
139
157
  async dbStats() {
@@ -141,7 +159,7 @@ var MClient = class {
141
159
  try {
142
160
  return await connection.db.stats();
143
161
  } finally {
144
- connection.client.close();
162
+ await connection.client.close();
145
163
  }
146
164
  }
147
165
  async getCollections() {
@@ -149,7 +167,7 @@ var MClient = class {
149
167
  try {
150
168
  return await connection.db.collections();
151
169
  } finally {
152
- connection.client.close();
170
+ await connection.client.close();
153
171
  }
154
172
  }
155
173
  };
@@ -159,8 +177,3 @@ export {
159
177
  MongoConnection,
160
178
  mongodbclient_default as default
161
179
  };
162
- /*!
163
- * @license mongodbclient
164
- * (c) 2020 tom
165
- * License: MIT
166
- */
package/package.json CHANGED
@@ -1,36 +1,34 @@
1
1
  {
2
2
  "name": "@tomsd/mongodbclient",
3
- "version": "3.0.14",
3
+ "version": "4.0.1",
4
4
  "description": "It's a handy mongodb client for easy-use.",
5
- "main": "dist/mongodbclient.cjs.js",
6
- "module": "dist/mongodbclient.esm.js",
7
- "types": "dist/esm/mongodbclient.d.ts",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/mongodbclient.d.ts",
8
+ "import": "./dist/mongodbclient.esm.js",
9
+ "require": "./dist/mogodbclient.cjs.js"
10
+ }
11
+ },
8
12
  "files": [
9
13
  "dist"
10
14
  ],
11
15
  "scripts": {
12
- "build": "tsup && tsc --project tsconfig.esm.json",
13
- "format": "npm run format:src && npm run format:test",
14
- "format:document": "prettier --write docs/**/*.html",
15
- "format:src": "prettier --write src/**/*.ts",
16
- "format:test": "prettier --write __test__/**/*.ts",
17
- "lint:src": "ESLINT_USE_FLAT_CONFIG=false eslint src/**/*.ts",
18
- "lint:test": "ESLINT_USE_FLAT_CONFIG=false eslint __test__/**/*.ts",
16
+ "build": "tsup",
17
+ "lint": "biome check",
19
18
  "prepare": "husky",
20
19
  "serve:doc": "mdbook --serve --directory docs",
20
+ "test:local": "docker run --name mongodb-mongodbclient --rm -d -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=user -e MONGO_INITDB_ROOT_PASSWORD=password mongodb/mongodb-community-server:6.0.3-ubuntu2204 && npx vitest run && docker container stop mongodb-mongodbclient",
21
21
  "test": "vitest"
22
22
  },
23
23
  "lint-staged": {
24
24
  "docs/**/*.html": [
25
- "npm run format:document"
25
+ "npm run lint"
26
26
  ],
27
27
  "src/**/*.ts": [
28
- "npm run lint:src",
29
- "npm run format:src"
28
+ "npm run lint"
30
29
  ],
31
30
  "__test__/**/*.ts": [
32
- "npm run lint:test",
33
- "npm run format:test"
31
+ "npm run lint"
34
32
  ]
35
33
  },
36
34
  "keywords": [
@@ -43,25 +41,19 @@
43
41
  "url": "https://github.com/tomsdoo/mongodbclient"
44
42
  },
45
43
  "dependencies": {
46
- "mongodb": "4.7.0",
47
- "uuid": "9.0.1"
44
+ "mongodb": "6.11.0",
45
+ "uuid": "11.0.3"
48
46
  },
49
47
  "devDependencies": {
50
- "@tomsd/md-book": "1.2.0",
51
- "@types/node": "20.12.12",
52
- "@types/uuid": "9.0.8",
53
- "@typescript-eslint/eslint-plugin": "7.9.0",
48
+ "@biomejs/biome": "1.9.4",
49
+ "@tomsd/md-book": "1.3.3",
50
+ "@types/node": "22.9.3",
51
+ "@types/uuid": "10.0.0",
54
52
  "dotenv": "16.4.5",
55
- "eslint": "8.57.0",
56
- "eslint-config-prettier": "9.1.0",
57
- "eslint-plugin-import": "2.29.1",
58
- "eslint-plugin-n": "17.7.0",
59
- "eslint-plugin-promise": "6.1.1",
60
- "husky": "9.0.11",
61
- "lint-staged": "15.2.2",
62
- "prettier": "3.2.5",
63
- "tsup": "8.0.2",
64
- "typescript": "5.4.5",
65
- "vitest": "1.6.0"
53
+ "husky": "9.1.7",
54
+ "lint-staged": "15.2.10",
55
+ "tsup": "8.3.5",
56
+ "typescript": "5.7.2",
57
+ "vitest": "2.1.5"
66
58
  }
67
59
  }
@@ -1,175 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { v4 as uuidv4 } from "uuid";
11
- // eslint-disable-next-line @typescript-eslint/no-var-requires
12
- const MongoClient = require("mongodb").MongoClient;
13
- export class MongoConnection {
14
- constructor(client, db, collection) {
15
- this._client = client;
16
- this._db = db;
17
- this._collection = collection;
18
- }
19
- get client() {
20
- return this._client;
21
- }
22
- get db() {
23
- return this._db;
24
- }
25
- get collection() {
26
- return this._collection;
27
- }
28
- }
29
- export class MClient {
30
- constructor(uri, db, collection) {
31
- this.m_uri = uri;
32
- this.m_db = db;
33
- this.m_collection = collection;
34
- }
35
- get uri() {
36
- return this.m_uri;
37
- }
38
- get db() {
39
- return this.m_db;
40
- }
41
- get collection() {
42
- return this.m_collection;
43
- }
44
- connect() {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- return yield this.getConnected();
47
- });
48
- }
49
- getConnected() {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- const client = new MongoClient(this.m_uri, { useUnifiedTopology: true });
52
- return client.connect().then((client) => {
53
- const db = client.db(this.m_db);
54
- const collection = db.collection(this.m_collection);
55
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
56
- return new MongoConnection(client, db, collection);
57
- });
58
- });
59
- }
60
- upsert(pobj) {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- const savingObj = Object.assign({ _id: uuidv4() }, pobj);
63
- const connection = yield this.getConnected();
64
- try {
65
- return yield connection.collection.updateOne({ _id: savingObj._id }, { $set: savingObj }, { upsert: true, writeConcern: { w: 1 } });
66
- }
67
- finally {
68
- connection.client.close();
69
- }
70
- });
71
- }
72
- read() {
73
- return __awaiter(this, arguments, void 0, function* (condition = {}, opt) {
74
- const connection = yield this.getConnected();
75
- try {
76
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
77
- return yield connection.collection.find(condition, opt).toArray();
78
- }
79
- finally {
80
- connection.client.close();
81
- }
82
- });
83
- }
84
- distinct(key_1) {
85
- return __awaiter(this, arguments, void 0, function* (key, condition = {}) {
86
- const connection = yield this.getConnected();
87
- try {
88
- // eslint-disable-next-line
89
- return (yield connection.collection.distinct(key,
90
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
91
- condition));
92
- }
93
- finally {
94
- connection.client.close();
95
- }
96
- });
97
- }
98
- remove(condition) {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- const connection = yield this.getConnected();
101
- try {
102
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
103
- return yield connection.collection.deleteMany(condition, {
104
- writeConcern: { w: 1 },
105
- });
106
- }
107
- finally {
108
- connection.client.close();
109
- }
110
- });
111
- }
112
- stats() {
113
- return __awaiter(this, void 0, void 0, function* () {
114
- const connection = yield this.getConnected();
115
- try {
116
- return yield connection.collection.stats();
117
- }
118
- finally {
119
- connection.client.close();
120
- }
121
- });
122
- }
123
- count() {
124
- return __awaiter(this, arguments, void 0, function* (condition = {}) {
125
- const connection = yield this.getConnected();
126
- try {
127
- // eslint-disable-next-line
128
- return (yield connection.collection.countDocuments(
129
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
130
- condition));
131
- }
132
- finally {
133
- connection.client.close();
134
- }
135
- });
136
- }
137
- insertMany(items) {
138
- return __awaiter(this, void 0, void 0, function* () {
139
- const connection = yield this.getConnected();
140
- const savingItems = items.map((item) => (Object.assign({ _id: uuidv4() }, item)));
141
- try {
142
- // eslint-disable-next-line
143
- return yield connection.collection.insertMany(savingItems, {
144
- writeConcern: { w: 1 },
145
- });
146
- }
147
- finally {
148
- connection.client.close();
149
- }
150
- });
151
- }
152
- dbStats() {
153
- return __awaiter(this, void 0, void 0, function* () {
154
- const connection = yield this.getConnected();
155
- try {
156
- return yield connection.db.stats();
157
- }
158
- finally {
159
- connection.client.close();
160
- }
161
- });
162
- }
163
- getCollections() {
164
- return __awaiter(this, void 0, void 0, function* () {
165
- const connection = yield this.getConnected();
166
- try {
167
- return yield connection.db.collections();
168
- }
169
- finally {
170
- connection.client.close();
171
- }
172
- });
173
- }
174
- }
175
- export default MClient;