Permalink
Browse files

Removed deprecated streamRecords from cursor

  • Loading branch information...
1 parent 62ba85d commit 918560f12cab2c7a3768415ddf4a0fb65456c707 @christkv christkv committed Apr 5, 2013
@@ -1,43 +0,0 @@
-var Db = require('../lib/mongodb').Db,
- Server = require('../lib/mongodb').Server,
- Cursor = require('../lib/mongodb').Cursor,
- Collection = require('../lib/mongodb').Collection,
- sys = require('util'),
- debug = require('util').debug,
- inspect = require('util').inspect;
-
-var parser = require('../lib/mongodb').BSONPure;
-var objectID = require('../lib/mongodb').ObjectID;
-
-var db = new Db('streaming_benchmark', new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize:4}), {})
-// Open the db
-db.open(function(err, client) {
- client.collection('streaming_benchmark', function(err, collection) {
- collection.remove({}, function(err, result) {
- // Benchmark
- var started_at = new Date().getTime();
- // Add documents
- for(var i = 0; i < 100000; i++) {
- // for(var i = 0; i < 10000; i++) {
- collection.save({'i':i, 'a':i, 'c':i, 'd':{'i':i}}, function(err, result){});
- }
- sys.puts("save recs: " + ((new Date().getTime() - started_at)/1000) + "seconds");
-
- // Benchmark
- var started_at = new Date().getTime();
- var count = 0;
- collection.find(function(err, cursor) {
- var stream = cursor.streamRecords(function(er,item) {});
- stream.addListener('end', function() {
- client.close();
- });
- stream.addListener('data',function(data){
- if(count == 0) started_at = new Date().getTime();
- count++;
- if ((count%10000)==0) sys.puts("recs:" + count + " :: " +
- ((new Date().getTime() - started_at)/10000) + "seconds");
- });
- });
- })
- })
-});
View
@@ -823,80 +823,6 @@ Cursor.prototype.explain = function(callback) {
};
/**
- * @ignore
- */
-Cursor.prototype.streamRecords = function(options) {
- console.log("[WARNING] streamRecords method is deprecated, please use stream method which is much faster");
- var args = Array.prototype.slice.call(arguments, 0);
- options = args.length ? args.shift() : {};
-
- var
- self = this,
- stream = new process.EventEmitter(),
- recordLimitValue = this.limitValue || 0,
- emittedRecordCount = 0,
- queryCommand = generateQueryCommand(self);
-
- // see http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol
- queryCommand.numberToReturn = options.fetchSize ? options.fetchSize : 500;
- // Execute the query
- execute(queryCommand);
-
- function execute(command) {
- self.db._executeQueryCommand(command, {exhaust: self.exhaust, read:self.read, raw:self.raw, connection:self.connection}, function(err,result) {
- if(err) {
- stream.emit('error', err);
- self.close(function(){});
- return;
- }
-
- if (!self.queryRun && result) {
- self.queryRun = true;
- self.cursorId = result.cursorId;
- self.state = Cursor.OPEN;
- self.getMoreCommand = new GetMoreCommand(self.db, self.collectionName, queryCommand.numberToReturn, result.cursorId);
- }
-
- var resflagsMap = {
- CursorNotFound:1<<0,
- QueryFailure:1<<1,
- ShardConfigStale:1<<2,
- AwaitCapable:1<<3
- };
-
- if(result.documents && result.documents.length && !(result.responseFlag & resflagsMap.QueryFailure)) {
- try {
- result.documents.forEach(function(doc){
- if(recordLimitValue && emittedRecordCount>=recordLimitValue) {
- throw("done");
- }
- emittedRecordCount++;
- stream.emit('data', doc);
- });
- } catch(err) {
- if (err != "done") { throw err; }
- else {
- self.close(function(){
- stream.emit('end', recordLimitValue);
- });
- self.close(function(){});
- return;
- }
- }
- // rinse & repeat
- execute(self.getMoreCommand);
- } else {
- self.close(function(){
- stream.emit('end', recordLimitValue);
- });
- }
- });
- }
-
- return stream;
-};
-
-/**
* Returns a Node ReadStream interface for this cursor.
*
* Options
@@ -1762,51 +1762,6 @@ exports.shouldCorrectlyPeformSimpleExplainCursor = function(configuration, test)
}
/**
- * A simple example showing the use of the cursor streamRecords function.
- *
- * @_class cursor
- * @_function streamRecords
- * @ignore
- */
-exports.shouldStreamDocumentsUsingTheStreamRecords = function(configuration, test) {
- var db = configuration.newDbInstance({w:1}, {poolSize:1, auto_reconnect:false});
-
- // DOC_LINE var db = new Db('test', new Server('locahost', 27017));
- // DOC_START
- // Establish connection to db
- db.open(function(err, db) {
-
- // Create a lot of documents to insert
- var docs = []
- for(var i = 0; i < 100; i++) {
- docs.push({'a':i})
- }
-
- // Create a collection
- db.createCollection('test_streamingRecords_function', function(err, collection) {
- test.equal(null, err);
-
- // Insert documents into collection
- collection.insert(docs, {w:1}, function(err, ids) {
- // Peform a find to get a cursor
- var stream = collection.find().streamRecords({fetchSize:1000});
-
- // Execute find on all the documents
- stream.on('end', function() {
- db.close();
- test.done();
- });
-
- stream.on('data', function(data) {
- test.ok(data != null);
- });
- });
- });
- });
- // DOC_END
-}
-
-/**
* A simple example showing the use of the cursor stream function.
*
* @_class cursor
@@ -288,80 +288,6 @@ exports.shouldTriggerMassiveAmountOfGetMores = function(configuration, test) {
});
}
-exports.shouldStreamRecordsCallsDataTheRightNumberOfTimes = function(configuration, test) {
- var client = configuration.db();
-
- client.createCollection('test_stream_records', function(err, collection) {
-
- collection.insert([{'a':1}, {'b' : 2}, {'c' : 3}, {'d' : 4}, {'e' : 5}], {w:1}, function(err, ids) {
- var stream = collection.find({}, {'limit' : 3}).streamRecords();
- var callsToEnd = 0;
- stream.on('end', function() {
- test.done();
- });
-
- var callsToData = 0;
- stream.on('data',function(data){
- callsToData += 1;
- test.ok(callsToData <= 3);
- });
- });
- });
-}
-
-exports.shouldStreamRecordsCallsEndTheRightNumberOfTimes = function(configuration, test) {
- var client = configuration.db();
-
- client.createCollection('test_stream_records', function(err, collection) {
-
- collection.insert([{'a':1}, {'b' : 2}, {'c' : 3}, {'d' : 4}, {'e' : 5}], {w:1}, function(err, ids) {
- var cursor = collection.find({}, {'limit' : 3});
- var stream = cursor.streamRecords(function(er,item) {});
- var callsToEnd = 0;
- stream.on('end', function() {
- callsToEnd += 1;
- test.equal(1, callsToEnd);
- setTimeout(function() {
- // Let's close the db
- if (callsToEnd == 1) {
- test.done();
- }
- }.bind(this), 1000);
- });
-
- stream.on('data',function(data){ /* nothing here */ });
- });
- });
-}
-
-// exports.shouldStreamDocumentsWithLimitForFetching = function(configuration, test) {
-// var client = configuration.db();
-// var docs = []
-
-// for(var i = 0; i < 3000; i++) {
-// docs.push({'a':i})
-// }
-
-// client.createCollection('test_streaming_function_with_limit_for_fetching', function(err, collection) {
-
-// collection.insert(docs, {w:1}, function(err, ids) {
-// var cursor = collection.find({});
-// // Execute find on all the documents
-// var stream = cursor.streamRecords({fetchSize:1000});
-// var callsToEnd = 0;
-// stream.on('end', function() {
-// test.done();
-// });
-
-// var callsToData = 0;
-// stream.on('data',function(data){
-// callsToData += 1;
-// test.ok(callsToData <= 3000);
-// });
-// });
-// });
-// }
-
exports.shouldStreamDocumentsAcrossGetMoreCommandAndCountCorrectly = function(configuration, test) {
var ObjectID = configuration.getMongoPackage().ObjectID
, Binary = configuration.getMongoPackage().Binary;

0 comments on commit 918560f

Please sign in to comment.