<commit_before># Mongo Driver and Mongo DB 2.6 Features

MongoDB 2.6 introduces some new powerful features that are reflected in the 1.4 driver release. These include.

* Aggregation cursors
* Per query timeouts **maxTimeMS**
* Ordered and Unordered bulk operations
* A parallelCollectionScan command for fast reading of an entire collection
* Integrated text search in the query language

Moreover the driver includes a whole slew of minor and major bug fixes and features. Some of the more noteworthy features include.

* Better support for domains in node.js
* Reconnect events for replicaset and mongos connections
* Replicaset emits "joined" and "left" events when new server join or leave the set
* Added **bufferMaxEntries** entry to allow tuning on how long driver keeps waiting for servers to come back up (default is until memory exhaustion)
* Upgraded BSON parser to rely on 0.2.6 returning to using **nan** package

Let's look at the main things in 2.6 features one by one.

## Aggregation cursors

The addition off aggregation cursors to MongoDB 2.6 now means that applications can disregard the previous max result limit of 16MB. Let's look at a simple use of the aggregation cursor.

		var MongoClient = require('mongodb').MongoClient;
		 
		MongoClient.connect("mongodb://localhost:27017/test", function(err, db) {
			// Get an aggregation cursor
			var cursor = db.collection('data').aggregate([
					{$match: {}}
				], {
		        allowDiskUsage: true
		      , cursor: {batchSize: 1000}		
				});

			// Use cursor as stream
			cursor.on('data', function(data) {
				console.dir(data);
			});

			cursor.on('end', function() {
				db.close();
			});
		});

As one can see the cursor implements the **Readable** stream interface for 0.10.X or higher. For 2.4 the driver will emulate the cursor behavior by wrapping the result document.

## maxTimeMS

One feature that has requested often is the ability to timeout individual queries. In MongoDB 2.6 it's finally arrived and is known as the **maxTimeMS** option. Let's take a look at a simple usage of the property with a query.

		var MongoClient = require('mongodb').MongoClient;
		 
		MongoClient.connect("mongodb://localhost:27017/test", function(err, db) {
			// Get an aggregation cursor
			var cursor = db.collection('data')
				.find("$where": "sleep(100) || true")
				.maxTimeMS(50);

			// Get alll the items
			cursor.toArray(function(err, items) {<commit_msg>Fixed typo in article<commit_after># Mongo Driver and Mongo DB 2.6 Features

MongoDB 2.6 introduces some new powerful features that are reflected in the 1.4 driver release. These include.

* Aggregation cursors
* Per query timeouts **maxTimeMS**
* Ordered and Unordered bulk operations
* A parallelCollectionScan command for fast reading of an entire collection
* Integrated text search in the query language

Moreover the driver includes a whole slew of minor and major bug fixes and features. Some of the more noteworthy features include.

* Better support for domains in node.js
* Reconnect events for replicaset and mongos connections
* Replicaset emits "joined" and "left" events when new server join or leave the set
* Added **bufferMaxEntries** entry to allow tuning on how long driver keeps waiting for servers to come back up (default is until memory exhaustion)
* Upgraded BSON parser to rely on 0.2.6 returning to using **nan** package

Let's look at the main things in 2.6 features one by one.

## Aggregation cursors

The addition off aggregation cursors to MongoDB 2.6 now means that applications can disregard the previous max result limit of 16MB. Let's look at a simple use of the aggregation cursor.

		var MongoClient = require('mongodb').MongoClient;
		 
		MongoClient.connect("mongodb://localhost:27017/test", function(err, db) {
			// Get an aggregation cursor
			var cursor = db.collection('data').aggregate([
					{$match: {}}
				], {
		        allowDiskUsage: true
		      , cursor: {batchSize: 1000}		
				});

			// Use cursor as stream
			cursor.on('data', function(data) {
				console.dir(data);
			});

			cursor.on('end', function() {
				db.close();
			});
		});

As one can see the cursor implements the **Readable** stream interface for 0.10.X or higher. For 2.4 the driver will emulate the cursor behavior by wrapping the result document.

## maxTimeMS

One feature that has requested often is the ability to timeout individual queries. In MongoDB 2.6 it's finally arrived and is known as the **maxTimeMS** option. Let's take a look at a simple usage of the property with a query.

		var MongoClient = require('mongodb').MongoClient;
		 
		MongoClient.connect("mongodb://localhost:27017/test", function(err, db) {
			// Get an aggregation cursor
			var cursor = db.collection('data')
				.find("$where": "sleep(1000) || true")
				.maxTimeMS(50);

			// Get alll the items
			cursor.toArray(function(err, items) {
{'fraction_non_alphanumeric': 0.08631622008590714, 'fraction_numerical': 0.016976886888934343, 'mean_word_length': 3.8320158102766797, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7049147', 'n_tokens_mistral': 1554, 'n_tokens_neox': 1294, 'n_words': 611}