whether run interactively in the mongo shell or non-interactively in a script. In previous versions, these methods exhibited a “fire-and-forget” behavior. 668 

• Existing scripts for the mongo shell that used these methods will now observe safe writes which take longer than the previous “fire-and-forget” behavior. 

• The write methods now return a WriteResult object that contains the results of the operation, in- cluding any write errors and write concern errors, and obviates the need to call getLastError com- mand to get the status of the results. See db.collection.insert() , db.collection.update() , db.collection.save() and db.collection.remove() for details. 

• In sharded environments, mongos no longer supports “fire-and-forget” behavior. This limits throughput when writing data to sharded clusters. 

Solution Scripts that used these mongo shell methods for bulk write operations with “fire-and-forget” behavior should use the Bulk() methods. 

In sharded environments, applications using any driver or mongo shell should use Bulk() methods for optimal performance when inserting or modifying groups of documents. 

For example, instead of: 

for ( var i = 1; i <= 1000000; i++) { db.test.insert( { x : i } ); } 

In MongoDB 2.6, replace with Bulk() operation: 

var bulk = db.test.initializeUnorderedBulkOp(); for ( var i = 1; i <= 1000000; i++) { bulk.insert( { x : i} ); } bulk.execute( { w: 1 } ); 

Bulk method returns a BulkWriteResult object that contains the result of the operation. 

See also: 

New Write Operation Protocol (page 852), Bulk() , Bulk.execute() , db.collection.initializeUnorderedBulkOp() , db.collection.initializeOrderedBulkOp() 

## db.collection.aggregate() Change 

Description The db.collection.aggregate() method in the mongo shell defaults to returning a cursor to the results set. This change enables the aggregation pipeline to return result sets of any size and requires cursor iteration to access the result set. For example: 

var myCursor = db.orders.aggregate( [ { $group: { _id: "$cust_id", total: { $sum: "$price" } } } ] ); 

