7ba04cf5adccc4a2766d15583ac4047aaf054b58
[aai/esr-gui.git] /
1 'use strict';
2
3 /**
4  * Module dependencies
5  */
6
7 var Collection = require('./collection');
8 var utils = require('../utils');
9
10 function NodeCollection (col) {
11   this.collection = col;
12   this.collectionName = col.collectionName;
13 }
14
15 /**
16  * inherit from collection base class
17  */
18
19 utils.inherits(NodeCollection, Collection);
20
21 /**
22  * find(match, options, function(err, docs))
23  */
24
25 NodeCollection.prototype.find = function (match, options, cb) {
26   this.collection.find(match, options, function (err, cursor) {
27     if (err) return cb(err);
28
29     cursor.toArray(cb);
30   });
31 }
32
33 /**
34  * findOne(match, options, function(err, doc))
35  */
36
37 NodeCollection.prototype.findOne = function (match, options, cb) {
38   this.collection.findOne(match, options, cb);
39 }
40
41 /**
42  * count(match, options, function(err, count))
43  */
44
45 NodeCollection.prototype.count = function (match, options, cb) {
46   this.collection.count(match, options, cb);
47 }
48
49 /**
50  * distinct(prop, match, options, function(err, count))
51  */
52
53 NodeCollection.prototype.distinct  = function (prop, match, options, cb) {
54   this.collection.distinct(prop, match, options, cb);
55 }
56
57 /**
58  * update(match, update, options, function(err[, result]))
59  */
60
61 NodeCollection.prototype.update = function (match, update, options, cb) {
62   this.collection.update(match, update, options, cb);
63 }
64
65 /**
66  * remove(match, options, function(err[, result])
67  */
68
69 NodeCollection.prototype.remove = function (match, options, cb) {
70   this.collection.remove(match, options, cb);
71 }
72
73 /**
74  * findAndModify(match, update, options, function(err, doc))
75  */
76
77 NodeCollection.prototype.findAndModify = function (match, update, options, cb) {
78   var sort = Array.isArray(options.sort) ? options.sort : [];
79   this.collection.findAndModify(match, sort, update, options, cb);
80 }
81
82 /**
83  * var stream = findStream(match, findOptions, streamOptions)
84  */
85
86 NodeCollection.prototype.findStream = function(match, findOptions, streamOptions) {
87   return this.collection.find(match, findOptions);
88 }
89
90 /**
91  * var cursor = findCursor(match, findOptions)
92  */
93
94 NodeCollection.prototype.findCursor = function(match, findOptions) {
95   return this.collection.find(match, findOptions);
96 }
97
98 /**
99  * aggregation(operators..., function(err, doc))
100  * TODO
101  */
102
103 /**
104  * Expose
105  */
106
107 module.exports = exports = NodeCollection;
108