From 09f262ab8c19b6790707cdaf565992833f36035c Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Fri, 29 Apr 2022 20:07:08 +0300 Subject: [PATCH] options for sorting, skipping and limit in mongo --- src/structure/storage/interfaces/MongodbTable.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/structure/storage/interfaces/MongodbTable.js b/src/structure/storage/interfaces/MongodbTable.js index a2c0768..871cdc0 100644 --- a/src/structure/storage/interfaces/MongodbTable.js +++ b/src/structure/storage/interfaces/MongodbTable.js @@ -13,11 +13,15 @@ class MongodbTable { //Data Search - async find(query, opts = {}) { //opts: { projection: ... } + async find(query, opts = {}, { sort, skip, limit } = {}) { //opts: { projection: ... } query = this._handleData(query); if (!this.provider._initialized) return Promise.reject(new Error('MongoDB is not connected.')); const cursor = await this.collection.find(query, opts); + if (sort) cursor.sort(sort); + if (skip) cursor.skip(skip); + if (limit) cursor.limit(limit); + return cursor.toArray(); }