Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. async textSearch(row, page, param, project, sortBy) {
  2. const ctx = 'mongodb-findAllData';
  3. const dbName = await this.getDatabase();
  4. const result = await mongoConnection.getConnection(this.config);
  5. if (result.err) {
  6. logger.log(ctx, result.err.message, 'Error mongodb connection');
  7. return result;
  8. }
  9. try {
  10. const cacheConnection = result.data.db;
  11. const connection = cacheConnection.db(dbName);
  12. const db = connection.collection(this.collectionName);
  13. const parameterPage = row * (page - 1);
  14. const recordset = await db.find(param).project(project).sort(sortBy).limit(row).skip(parameterPage)
  15. .toArray();
  16. if (validate.isEmpty(recordset)) {
  17. return wrapper.error('Data Not Found', 'Please Try Another Input', 404);
  18. }
  19. return wrapper.data(recordset);
  20.  
  21. } catch (err) {
  22. logger.log(ctx, err.message, 'Error upsert data in mongodb');
  23. return wrapper.error('Error Mongo', `${err.message}`, 409);
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement