mongodb 2.1.0-alpha → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/HISTORY.md +574 -429
  2. package/Makefile +2 -5
  3. package/README.md +108 -15
  4. package/conf.json +17 -13
  5. package/index.js +13 -2
  6. package/lib/admin.js +113 -47
  7. package/lib/aggregation_cursor.js +56 -28
  8. package/lib/apm.js +608 -0
  9. package/lib/bulk/common.js +7 -7
  10. package/lib/bulk/ordered.js +56 -17
  11. package/lib/bulk/unordered.js +52 -14
  12. package/lib/collection.js +671 -212
  13. package/lib/command_cursor.js +60 -32
  14. package/lib/cursor.js +313 -115
  15. package/lib/db.js +264 -105
  16. package/lib/gridfs/chunk.js +26 -29
  17. package/lib/gridfs/grid_store.js +150 -64
  18. package/lib/gridfs-stream/download.js +310 -0
  19. package/lib/gridfs-stream/index.js +335 -0
  20. package/lib/gridfs-stream/upload.js +450 -0
  21. package/lib/metadata.js +64 -0
  22. package/lib/mongo_client.js +69 -39
  23. package/lib/mongos.js +65 -20
  24. package/lib/replset.js +69 -34
  25. package/lib/server.js +35 -1
  26. package/lib/topology_base.js +22 -10
  27. package/lib/url_parser.js +111 -13
  28. package/lib/utils.js +9 -8
  29. package/mongolabs.js +427 -0
  30. package/package.json +8 -6
  31. package/t.js +68 -51
  32. package/test.js +12 -0
  33. package/test_boot/boot.sh +3 -0
  34. package/test_boot/ca.pem +49 -0
  35. package/test_boot/client.pem +48 -0
  36. package/test_boot/client_password.pem +51 -0
  37. package/test_boot/connect.js +29 -0
  38. package/test_boot/data/WiredTiger +2 -0
  39. package/test_boot/data/WiredTiger.lock +1 -0
  40. package/test_boot/data/WiredTiger.turtle +6 -0
  41. package/test_boot/data/WiredTiger.wt +0 -0
  42. package/test_boot/data/WiredTigerLAS.wt +0 -0
  43. package/test_boot/data/_mdb_catalog.wt +0 -0
  44. package/test_boot/data/collection-0-757073248613337118.wt +0 -0
  45. package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-44-37Z-00000 +0 -0
  46. package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-45-15Z-00000 +0 -0
  47. package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-46-31Z-00000 +0 -0
  48. package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-47-25Z-00000 +0 -0
  49. package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-49-07Z-00000 +0 -0
  50. package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-50-41Z-00000 +0 -0
  51. package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-50-53Z-00000 +0 -0
  52. package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-52-31Z-00000 +0 -0
  53. package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-54-53Z-00000 +0 -0
  54. package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-55-09Z-00000 +0 -0
  55. package/test_boot/data/diagnostic.data/metrics.2015-10-07T14-55-38Z-00000 +0 -0
  56. package/test_boot/data/index-1-757073248613337118.wt +0 -0
  57. package/test_boot/data/mongod.lock +0 -0
  58. package/test_boot/data/sizeStorer.wt +0 -0
  59. package/test_boot/data/storage.bson +0 -0
  60. package/test_boot/server_password.pem +51 -0
  61. package/.travis.yml +0 -10
  62. package/t1.js +0 -59
  63. package/wercker.yml +0 -19
@@ -11,17 +11,17 @@ var inherits = require('util').inherits
11
11
  , ReadPreference = require('./read_preference')
12
12
  , MongoError = require('mongodb-core').MongoError
13
13
  , Readable = require('stream').Readable || require('readable-stream').Readable
14
- // , CoreCursor = require('mongodb-core').Cursor
14
+ , Define = require('./metadata')
15
15
  , CoreCursor = require('./cursor')
16
16
  , Query = require('mongodb-core').Query
17
17
  , CoreReadPreference = require('mongodb-core').ReadPreference;
18
18
 
19
19
  /**
20
- * @fileOverview The **CommandCursor** class is an internal class that embodies a
21
- * generalized cursor based on a MongoDB command allowing for iteration over the
22
- * results returned. It supports one by one document iteration, conversion to an
20
+ * @fileOverview The **CommandCursor** class is an internal class that embodies a
21
+ * generalized cursor based on a MongoDB command allowing for iteration over the
22
+ * results returned. It supports one by one document iteration, conversion to an
23
23
  * array or can be iterated as a Node 0.10.X or higher stream
24
- *
24
+ *
25
25
  * **CommandCursor Cannot directly be instantiated**
26
26
  * @example
27
27
  * var MongoClient = require('mongodb').MongoClient,
@@ -37,7 +37,7 @@ var inherits = require('util').inherits
37
37
  * , {a:2, b:2}, {a:3, b:3}
38
38
  * , {a:4, b:4}], {w:1}, function(err, result) {
39
39
  * test.equal(null, err);
40
- *
40
+ *
41
41
  * // List the database collections available
42
42
  * db.listCollections().toArray(function(err, items) {
43
43
  * test.equal(null, err);
@@ -104,7 +104,7 @@ var CommandCursor = function(bson, ns, cmd, options, topology, topologyOptions)
104
104
  // Topology Options
105
105
  , topologyOptions: topologyOptions
106
106
  // Promise library
107
- , promiseLibrary: promiseLibrary
107
+ , promiseLibrary: promiseLibrary
108
108
  }
109
109
  }
110
110
 
@@ -137,17 +137,42 @@ var CommandCursor = function(bson, ns, cmd, options, topology, topologyOptions)
137
137
  */
138
138
 
139
139
  // Inherit from Readable
140
- inherits(CommandCursor, Readable);
140
+ inherits(CommandCursor, Readable);
141
141
 
142
142
  // Set the methods to inherit from prototype
143
143
  var methodsToInherit = ['_next', 'next', 'each', 'forEach', 'toArray'
144
- , 'rewind', 'bufferedCount', 'readBufferedDocuments', 'close', 'isClosed'];
144
+ , 'rewind', 'bufferedCount', 'readBufferedDocuments', 'close', 'isClosed', 'kill'
145
+ , '_find', '_getmore', '_killcursor', 'isDead', 'explain', 'isNotified', 'isKilled'];
145
146
 
146
147
  // Only inherit the types we need
147
148
  for(var i = 0; i < methodsToInherit.length; i++) {
148
149
  CommandCursor.prototype[methodsToInherit[i]] = CoreCursor.prototype[methodsToInherit[i]];
149
150
  }
150
151
 
152
+ var define = CommandCursor.define = new Define('CommandCursor', CommandCursor, true);
153
+
154
+ /**
155
+ * Set the ReadPreference for the cursor.
156
+ * @method
157
+ * @param {(string|ReadPreference)} readPreference The new read preference for the cursor.
158
+ * @throws {MongoError}
159
+ * @return {Cursor}
160
+ */
161
+ CommandCursor.prototype.setReadPreference = function(r) {
162
+ if(this.s.state == CommandCursor.CLOSED || this.isDead()) throw MongoError.create({message: "Cursor is closed", driver:true});
163
+ if(this.s.state != CommandCursor.INIT) throw MongoError.create({message: 'cannot change cursor readPreference after cursor has been accessed', driver:true});
164
+
165
+ if(r instanceof ReadPreference) {
166
+ this.s.options.readPreference = new CoreReadPreference(r.mode, r.tags);
167
+ } else {
168
+ this.s.options.readPreference = new CoreReadPreference(r);
169
+ }
170
+
171
+ return this;
172
+ }
173
+
174
+ define.classMethod('setReadPreference', {callback: false, promise:false, returns: [CommandCursor]});
175
+
151
176
  /**
152
177
  * Set the batch size for the cursor.
153
178
  * @method
@@ -156,13 +181,15 @@ for(var i = 0; i < methodsToInherit.length; i++) {
156
181
  * @return {CommandCursor}
157
182
  */
158
183
  CommandCursor.prototype.batchSize = function(value) {
159
- if(this.s.state == CommandCursor.CLOSED || this.isDead()) throw new MongoError("Cursor is closed");
160
- if(typeof value != 'number') throw new MongoError("batchSize requires an integer");
184
+ if(this.s.state == CommandCursor.CLOSED || this.isDead()) throw MongoError.create({message: "Cursor is closed", driver:true});
185
+ if(typeof value != 'number') throw MongoError.create({message: "batchSize requires an integer", driver:true});
161
186
  if(this.s.cmd.cursor) this.s.cmd.cursor.batchSize = value;
162
187
  this.setCursorBatchSize(value);
163
188
  return this;
164
189
  }
165
190
 
191
+ define.classMethod('batchSize', {callback: false, promise:false, returns: [CommandCursor]});
192
+
166
193
  /**
167
194
  * Add a maxTimeMS stage to the aggregation pipeline
168
195
  * @method
@@ -176,30 +203,31 @@ CommandCursor.prototype.maxTimeMS = function(value) {
176
203
  return this;
177
204
  }
178
205
 
206
+ define.classMethod('maxTimeMS', {callback: false, promise:false, returns: [CommandCursor]});
207
+
179
208
  CommandCursor.prototype.get = CommandCursor.prototype.toArray;
180
209
 
210
+ define.classMethod('get', {callback: true, promise:false});
211
+
212
+ // Inherited methods
213
+ define.classMethod('toArray', {callback: true, promise:true});
214
+ define.classMethod('each', {callback: true, promise:false});
215
+ define.classMethod('forEach', {callback: true, promise:false});
216
+ define.classMethod('next', {callback: true, promise:true});
217
+ define.classMethod('close', {callback: true, promise:true});
218
+ define.classMethod('isClosed', {callback: false, promise:false, returns: [Boolean]});
219
+ define.classMethod('rewind', {callback: false, promise:false});
220
+ define.classMethod('bufferedCount', {callback: false, promise:false, returns: [Number]});
221
+ define.classMethod('readBufferedDocuments', {callback: false, promise:false, returns: [Array]});
222
+
181
223
  /**
182
224
  * Get the next available document from the cursor, returns null if no more documents are available.
183
225
  * @function CommandCursor.prototype.next
184
- * @param {CommandCursor~resultCallback} callback The result callback.
226
+ * @param {CommandCursor~resultCallback} [callback] The result callback.
185
227
  * @throws {MongoError}
186
228
  * @return {Promise} returns Promise if no callback passed
187
229
  */
188
230
 
189
- /**
190
- * Set the new batchSize of the cursor
191
- * @function CommandCursor.prototype.setBatchSize
192
- * @param {number} value The new batchSize for the cursor
193
- * @return {null}
194
- */
195
-
196
- /**
197
- * Get the batchSize of the cursor
198
- * @function CommandCursor.prototype.batchSize
199
- * @param {number} value The current batchSize for the cursor
200
- * @return {null}
201
- */
202
-
203
231
  /**
204
232
  * The callback format for results
205
233
  * @callback CommandCursor~toArrayResultCallback
@@ -212,7 +240,7 @@ CommandCursor.prototype.get = CommandCursor.prototype.toArray;
212
240
  * is enough memory to store the results. Note that the array only contain partial
213
241
  * results when this cursor had been previouly accessed.
214
242
  * @method CommandCursor.prototype.toArray
215
- * @param {CommandCursor~toArrayResultCallback} callback The result callback.
243
+ * @param {CommandCursor~toArrayResultCallback} [callback] The result callback.
216
244
  * @throws {MongoError}
217
245
  * @return {Promise} returns Promise if no callback passed
218
246
  */
@@ -242,25 +270,25 @@ CommandCursor.prototype.get = CommandCursor.prototype.toArray;
242
270
  * @method CommandCursor.prototype.close
243
271
  * @param {CommandCursor~resultCallback} [callback] The result callback.
244
272
  * @return {Promise} returns Promise if no callback passed
245
- */
273
+ */
246
274
 
247
275
  /**
248
276
  * Is the cursor closed
249
277
  * @method CommandCursor.prototype.isClosed
250
278
  * @return {boolean}
251
- */
279
+ */
252
280
 
253
281
  /**
254
282
  * Clone the cursor
255
283
  * @function CommandCursor.prototype.clone
256
284
  * @return {CommandCursor}
257
- */
285
+ */
258
286
 
259
287
  /**
260
288
  * Resets the cursor
261
289
  * @function CommandCursor.prototype.rewind
262
290
  * @return {CommandCursor}
263
- */
291
+ */
264
292
 
265
293
  /**
266
294
  * The callback format for the forEach iterator method
@@ -287,4 +315,4 @@ CommandCursor.INIT = 0;
287
315
  CommandCursor.OPEN = 1;
288
316
  CommandCursor.CLOSED = 2;
289
317
 
290
- module.exports = CommandCursor;
318
+ module.exports = CommandCursor;