mongodb-ops 0.8.1 → 0.8.2

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.
@@ -86,6 +86,43 @@ class MongoDBToolSet extends MongoDBOps {
86
86
  return Promise.resolve(await MongoDBToolSet.getDataCount(this.collectionName, filter, this.connString));
87
87
  }
88
88
 
89
+ /**
90
+ * Static method - List record with optional no. of data counts
91
+ *
92
+ * @param {string} collectionName Collection name
93
+ * @param {object} [query] Query filter {@link https://docs.mongodb.com/manual/core/document/#document-query-filter}
94
+ * @param {object} [projection] Projection {@link https://docs.mongodb.com/manual/reference/method/db.collection.find/#find-projection}
95
+ * @param {object} [sort] Sort filter {@link https://docs.mongodb.com/manual/reference/method/cursor.sort/#cursor.sort}
96
+ * @param {object} [pagination] Pagination `E.g., { startIndex: 11, endIndex: 20 }`
97
+ * @param {boolean|string} [showCount] Set true to return the data with total_count which is the record count on the data by query
98
+ * @param {string} connString Database connection string
99
+ * @returns {promise} Promise with data object or array
100
+ */
101
+ static async list(collectionName, query, projection, sort, pagination, showCount, connString) {
102
+ if (["true", true].includes(showCount)) {
103
+ const [total_count, data] = await Promise.all([
104
+ MongoDBToolSet.getDataCount(collectionName, query, connString),
105
+ MongoDBToolSet.getDataByFilter(collectionName, query, projection, sort, pagination, connString)
106
+ ]);
107
+ return Promise.resolve({ total_count, data });
108
+ }
109
+ else { return Promise.resolve(await MongoDBToolSet.getDataByFilter(collectionName, query, projection, sort, pagination, connString)); }
110
+ }
111
+
112
+ /**
113
+ * Instance method - List record with optional no. of data counts
114
+ *
115
+ * @param {object} [query] Query filter {@link https://docs.mongodb.com/manual/core/document/#document-query-filter}
116
+ * @param {object} [projection] Projection {@link https://docs.mongodb.com/manual/reference/method/db.collection.find/#find-projection}
117
+ * @param {object} [sort] Sort filter {@link https://docs.mongodb.com/manual/reference/method/cursor.sort/#cursor.sort}
118
+ * @param {object} [pagination] Pagination `E.g., { startIndex: 11, endIndex: 20 }`
119
+ * @param {boolean|string} [showCount=false] Set true to return the data with total_count which is the record count on the data by query
120
+ * @returns {promise} Promise with data count
121
+ */
122
+ async list(query, projection, sort, pagination, showCount) {
123
+ return Promise.resolve(await MongoDBToolSet.list(this.collectionName, query, projection, sort, pagination, showCount, this.connString));
124
+ }
125
+
89
126
  /**
90
127
  * Static method - Get all data
91
128
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb-ops",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "Read and write ops for MongoDB",
5
5
  "main": "index.js",
6
6
  "scripts": {