Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async textSearch(row, page, param, project, sortBy) {
- const ctx = 'mongodb-findAllData';
- const dbName = await this.getDatabase();
- const result = await mongoConnection.getConnection(this.config);
- if (result.err) {
- logger.log(ctx, result.err.message, 'Error mongodb connection');
- return result;
- }
- try {
- const cacheConnection = result.data.db;
- const connection = cacheConnection.db(dbName);
- const db = connection.collection(this.collectionName);
- const parameterPage = row * (page - 1);
- const recordset = await db.find(param).project(project).sort(sortBy).limit(row).skip(parameterPage)
- .toArray();
- if (validate.isEmpty(recordset)) {
- return wrapper.error('Data Not Found', 'Please Try Another Input', 404);
- }
- return wrapper.data(recordset);
- } catch (err) {
- logger.log(ctx, err.message, 'Error upsert data in mongodb');
- return wrapper.error('Error Mongo', `${err.message}`, 409);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement