mongoplusplus 1.0.1 → 1.0.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.
Files changed (2) hide show
  1. package/mongoplus.js +15 -40
  2. package/package.json +28 -25
package/mongoplus.js CHANGED
@@ -188,7 +188,7 @@ class MongoModel {
188
188
 
189
189
  async findOne(dbIndex, filter, chain = {}) {
190
190
  var currentModel = this.model[dbIndex]
191
- var chain = pair.chain;
191
+
192
192
  if (chain.skip && chain.limit && chain.sort) {
193
193
  currentModel.findOne(filter).skip(chain.skip).limit(chain.limit).sort(chain.sort)
194
194
  } else if (chain.skip && chain.limit) {
@@ -211,7 +211,7 @@ class MongoModel {
211
211
 
212
212
  async find(dbIndex, filter, chain = {}) {
213
213
  var currentModel = this.model[dbIndex]
214
- var chain = pair.chain;
214
+
215
215
  if (chain.skip && chain.limit && chain.sort) {
216
216
  currentModel.find(filter).skip(chain.skip).limit(chain.limit).sort(chain.sort)
217
217
  } else if (chain.skip && chain.limit) {
@@ -231,47 +231,22 @@ class MongoModel {
231
231
  }
232
232
  //=======================
233
233
  async findById(dbIndex, filter, chain = {}) {
234
- var currentModel = this.model[dbIndex]
235
- var chain = pair.chain;
236
- if (chain.skip && chain.limit && chain.sort) {
237
- currentModel.findById(filter).skip(chain.skip).limit(chain.limit).sort(chain.sort)
238
- } else if (chain.skip && chain.limit) {
239
- return currentModel.findById(filter).skip(chain.skip).limit(chain.limit)
240
- }
241
- else if (chain.skip) {
242
- return currentModel.findById(filter).skip(chain.skip)
243
- }
244
-
245
- else if (chain.limit) {
246
- return currentModel.findById(filter).limit(chain.limit)
247
- } else {
248
- return currentModel.findById(filter);
234
+ const currentModel = this.model[dbIndex];
235
+
236
+ // Start with the base query
237
+ let query = currentModel.findById(filter);
238
+
239
+ // Dynamically apply chain options if they exist
240
+ for (const [key, value] of Object.entries(chain)) {
241
+ if (query[key]) {
242
+ query = query[key](value);
243
+ }
249
244
  }
250
-
251
-
245
+
246
+ return query;
252
247
  }
253
248
 
254
- //==========================
255
- async findById(dbIndex, filter, chain = {}) {
256
- var currentModel = this.model[dbIndex]
257
- var chain = pair.chain;
258
- if (chain.skip && chain.limit && chain.sort) {
259
- currentModel.findById(filter).skip(chain.skip).limit(chain.limit).sort(chain.sort)
260
- } else if (chain.skip && chain.limit) {
261
- return currentModel.findById(filter).skip(chain.skip).limit(chain.limit)
262
- }
263
- else if (chain.skip) {
264
- return currentModel.findById(filter).skip(chain.skip)
265
- }
266
-
267
- else if (chain.limit) {
268
- return currentModel.findById(filter).limit(chain.limit)
269
- } else {
270
- return currentModel.findById(filter);
271
- }
272
-
273
-
274
- }
249
+
275
250
  //====================
276
251
  async findByIdAndUpdate(dbIndex, id, update) {
277
252
  var currentModel = this.model[dbIndex]
package/package.json CHANGED
@@ -1,38 +1,41 @@
1
1
  {
2
2
  "name": "mongoplusplus",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "load balancing of read and write operations across multiple MongoDB servers ",
5
5
  "main": "mongoplus.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
8
8
  },
9
9
  "author": "somen das(somen6562@gmail.com)",
10
- "keywords": [ "MongoDB",
11
- "Database",
12
- "ORM",
13
- "Wrapper",
14
- "Mongoose",
15
- "Multi-Database",
16
- "Data Management",
17
- "Async Operations",
18
- "Scalable",
19
- "Readability",
20
- "Performance",
21
- "Node.js",
22
- "Worker Threads",
23
- "Connection Pooling",
24
- "Schema Management",
25
- "CRUD Operations",
26
- "Document-Oriented",
27
- "Distributed",
28
- "Replication",
29
- "Sharding",
30
- "load balancing",
31
- "multiple database",
32
- "Aggregation Framework"],
10
+ "keywords": [
11
+ "MongoDB",
12
+ "Database",
13
+ "ORM",
14
+ "Wrapper",
15
+ "Mongoose",
16
+ "Multi-Database",
17
+ "Data Management",
18
+ "Async Operations",
19
+ "Scalable",
20
+ "Readability",
21
+ "Performance",
22
+ "Node.js",
23
+ "Worker Threads",
24
+ "Connection Pooling",
25
+ "Schema Management",
26
+ "CRUD Operations",
27
+ "Document-Oriented",
28
+ "Distributed",
29
+ "Replication",
30
+ "Sharding",
31
+ "load balancing",
32
+ "multiple database",
33
+ "Aggregation Framework"
34
+ ],
33
35
  "license": "ISC",
34
36
  "dependencies": {
35
37
  "mongoose": "^6.3.5",
36
- "mongoose-sequence": "^5.3.1"
38
+ "mongoose-sequence": "^5.3.1",
39
+ "mongoplusplus": "^1.0.1"
37
40
  }
38
41
  }