node.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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, function(err, docs))
  14. */
  15. find(match, options, cb) {
  16. const cursor = this.collection.find(match, options);
  17. try {
  18. cursor.toArray(cb);
  19. } catch (error) {
  20. cb(error);
  21. }
  22. }
  23. /**
  24. * findOne(match, options, function(err, doc))
  25. */
  26. findOne(match, options, cb) {
  27. this.collection.findOne(match, options, cb);
  28. }
  29. /**
  30. * count(match, options, function(err, count))
  31. */
  32. count(match, options, cb) {
  33. this.collection.count(match, options, cb);
  34. }
  35. /**
  36. * distinct(prop, match, options, function(err, count))
  37. */
  38. distinct(prop, match, options, cb) {
  39. this.collection.distinct(prop, match, options, cb);
  40. }
  41. /**
  42. * update(match, update, options, function(err[, result]))
  43. */
  44. update(match, update, options, cb) {
  45. this.collection.update(match, update, options, cb);
  46. }
  47. /**
  48. * update(match, update, options, function(err[, result]))
  49. */
  50. updateMany(match, update, options, cb) {
  51. this.collection.updateMany(match, update, options, cb);
  52. }
  53. /**
  54. * update(match, update, options, function(err[, result]))
  55. */
  56. updateOne(match, update, options, cb) {
  57. this.collection.updateOne(match, update, options, cb);
  58. }
  59. /**
  60. * replaceOne(match, update, options, function(err[, result]))
  61. */
  62. replaceOne(match, update, options, cb) {
  63. this.collection.replaceOne(match, update, options, cb);
  64. }
  65. /**
  66. * deleteOne(match, options, function(err[, result])
  67. */
  68. deleteOne(match, options, cb) {
  69. this.collection.deleteOne(match, options, cb);
  70. }
  71. /**
  72. * deleteMany(match, options, function(err[, result])
  73. */
  74. deleteMany(match, options, cb) {
  75. this.collection.deleteMany(match, options, cb);
  76. }
  77. /**
  78. * remove(match, options, function(err[, result])
  79. */
  80. remove(match, options, cb) {
  81. this.collection.remove(match, options, cb);
  82. }
  83. /**
  84. * findOneAndDelete(match, options, function(err[, result])
  85. */
  86. findOneAndDelete(match, options, cb) {
  87. this.collection.findOneAndDelete(match, options, cb);
  88. }
  89. /**
  90. * findOneAndUpdate(match, update, options, function(err[, result])
  91. */
  92. findOneAndUpdate(match, update, options, cb) {
  93. this.collection.findOneAndUpdate(match, update, options, cb);
  94. }
  95. /**
  96. * var cursor = findCursor(match, options)
  97. */
  98. findCursor(match, options) {
  99. return this.collection.find(match, options);
  100. }
  101. /**
  102. * aggregation(operators..., function(err, doc))
  103. * TODO
  104. */
  105. }
  106. /**
  107. * Expose
  108. */
  109. module.exports = exports = NodeCollection;