mongoplusplus 1.0.2 → 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.
- package/mongoplus.js +13 -38
- package/package.json +1 -1
package/mongoplus.js
CHANGED
|
@@ -231,47 +231,22 @@ class MongoModel {
|
|
|
231
231
|
}
|
|
232
232
|
//=======================
|
|
233
233
|
async findById(dbIndex, filter, chain = {}) {
|
|
234
|
-
|
|
235
|
-
|
|
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);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
//==========================
|
|
255
|
-
async findById(dbIndex, filter, chain = {}) {
|
|
256
|
-
var currentModel = this.model[dbIndex]
|
|
234
|
+
const currentModel = this.model[dbIndex];
|
|
257
235
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
else if (chain.limit) {
|
|
268
|
-
return currentModel.findById(filter).limit(chain.limit)
|
|
269
|
-
} else {
|
|
270
|
-
return currentModel.findById(filter);
|
|
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
|
+
}
|
|
271
244
|
}
|
|
272
|
-
|
|
273
|
-
|
|
245
|
+
|
|
246
|
+
return query;
|
|
274
247
|
}
|
|
248
|
+
|
|
249
|
+
|
|
275
250
|
//====================
|
|
276
251
|
async findByIdAndUpdate(dbIndex, id, update) {
|
|
277
252
|
var currentModel = this.model[dbIndex]
|