options for sorting, skipping and limit in mongo

This commit is contained in:
Erik 2022-04-29 20:07:08 +03:00
parent 4ab77f9b71
commit 09f262ab8c
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -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();
}