node.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. 'use strict';
  2. /**
  3. * Module dependencies
  4. */
  5. const Collection = require('./collection');
  6. class NodeCollection extends Collection {
  7. constructor(col) {
  8. super();
  9. this.collection = col;
  10. this.collectionName = col.collectionName;
  11. }
  12. /**
  13. * find(match, options)
  14. */
  15. async find(match, options) {
  16. const cursor = this.collection.find(match, options);
  17. return cursor.toArray();
  18. }
  19. /**
  20. * findOne(match, options)
  21. */
  22. async findOne(match, options) {
  23. return this.collection.findOne(match, options);
  24. }
  25. /**
  26. * countDocuments(match, options)
  27. */
  28. async countDocuments(match, options) {
  29. return this.collection.countDocuments(match, options);
  30. }
  31. /**
  32. * estimatedDocumentCount(match, options)
  33. */
  34. async estimatedDocumentCount(match, options) {
  35. return this.collection.estimatedDocumentCount(match, options);
  36. }
  37. /**
  38. * distinct(prop, match, options)
  39. */
  40. async distinct(prop, match, options) {
  41. return this.collection.distinct(prop, match, options);
  42. }
  43. /**
  44. * updateMany(match, update, options)
  45. */
  46. async updateMany(match, update, options) {
  47. return this.collection.updateMany(match, update, options);
  48. }
  49. /**
  50. * updateOne(match, update, options)
  51. */
  52. async updateOne(match, update, options) {
  53. return this.collection.updateOne(match, update, options);
  54. }
  55. /**
  56. * replaceOne(match, update, options)
  57. */
  58. async replaceOne(match, update, options) {
  59. return this.collection.replaceOne(match, update, options);
  60. }
  61. /**
  62. * deleteOne(match, options)
  63. */
  64. async deleteOne(match, options) {
  65. return this.collection.deleteOne(match, options);
  66. }
  67. /**
  68. * deleteMany(match, options)
  69. */
  70. async deleteMany(match, options) {
  71. return this.collection.deleteMany(match, options);
  72. }
  73. /**
  74. * findOneAndDelete(match, options, function(err[, result])
  75. */
  76. async findOneAndDelete(match, options) {
  77. return this.collection.findOneAndDelete(match, options);
  78. }
  79. /**
  80. * findOneAndUpdate(match, update, options)
  81. */
  82. async findOneAndUpdate(match, update, options) {
  83. return this.collection.findOneAndUpdate(match, update, options);
  84. }
  85. /**
  86. * findOneAndReplace(match, update, options)
  87. */
  88. async findOneAndReplace(match, update, options) {
  89. return this.collection.findOneAndReplace(match, update, options);
  90. }
  91. /**
  92. * var cursor = findCursor(match, options)
  93. */
  94. findCursor(match, options) {
  95. return this.collection.find(match, options);
  96. }
  97. /**
  98. * aggregation(operators...)
  99. * TODO
  100. */
  101. }
  102. /**
  103. * Expose
  104. */
  105. module.exports = exports = NodeCollection;