Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SERVER-6802 allow bulk insert options from the shell

  • Loading branch information...
commit b9853301c32d9fde04fb9357834b7156ca7577df 1 parent b5c8d77
Greg Studer authored
View
2  jstests/basicb.js
@@ -3,5 +3,5 @@ t = db.basicb;
t.drop();
assert.throws( "t.insert( { '$a' : 5 } );" );
-t.insert( { '$a' : 5 } , true );
+t.insert( { '$a' : 5 } , 0, true );
View
2  jstests/insert2.js
@@ -3,6 +3,6 @@ t = db.insert2
t.drop()
assert.isnull( t.findOne() , "A" )
-t.insert( { z : 1 , $inc : { x : 1 } } , true );
+t.insert( { z : 1 , $inc : { x : 1 } } , 0, true );
assert.isnull( t.findOne() , "B" )
View
6 src/mongo/scripting/sm_db.cpp
@@ -479,7 +479,7 @@ namespace mongo {
JSBool mongo_insert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
try {
- smuassert( cx , "mongo_insert needs 2 args" , argc == 2 );
+ smuassert( cx , "mongo_insert needs 3 args" , argc == 3 );
smuassert( cx , "2nd param to insert has to be an object" , JSVAL_IS_OBJECT( argv[1] ) );
Convertor c( cx );
@@ -495,6 +495,8 @@ namespace mongo {
JSObject * insertObj = JSVAL_TO_OBJECT( argv[1] );
+ int flags = static_cast<int>( c.toNumber( argv[2] ) );
+
if( JS_IsArrayObject( cx, insertObj ) ){
vector<BSONObj> bos;
@@ -511,7 +513,7 @@ namespace mongo {
bos.push_back( c.toObject( el ) );
}
- conn->insert( ns, bos );
+ conn->insert( ns, bos, flags );
}
else {
BSONObj o = c.toObject( argv[1] );
View
9 src/mongo/shell/collection.js
@@ -162,12 +162,15 @@ DBCollection.prototype.findOne = function( query , fields, options ){
return ret;
}
-DBCollection.prototype.insert = function( obj , _allow_dot ){
+DBCollection.prototype.insert = function( obj , options, _allow_dot ){
if ( ! obj )
throw "no object passed to insert!";
if ( ! _allow_dot ) {
this._validateForStorage( obj );
}
+
+ if ( typeof( options ) == "undefined" ) options = 0;
+
if ( typeof( obj._id ) == "undefined" && ! Array.isArray( obj ) ){
var tmp = obj; // don't want to modify input
obj = {_id: new ObjectId()};
@@ -176,7 +179,7 @@ DBCollection.prototype.insert = function( obj , _allow_dot ){
}
}
this._db._initExtraInfo();
- this._mongo.insert( this._fullName , obj );
+ this._mongo.insert( this._fullName , obj, options );
this._lastID = obj._id;
this._db._getExtraInfo("Inserted");
}
@@ -320,7 +323,7 @@ DBCollection.prototype._indexSpec = function( keys, options ) {
DBCollection.prototype.createIndex = function( keys , options ){
var o = this._indexSpec( keys, options );
- this._db.getCollection( "system.indexes" ).insert( o , true );
+ this._db.getCollection( "system.indexes" ).insert( o , 0, true );
}
DBCollection.prototype.ensureIndex = function( keys , options ){
Please sign in to comment.
Something went wrong with that request. Please try again.