Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Spider Monkey: remove

  • Loading branch information...
commit 26c4b0139f0a96891796c3c54fe821c819db4697 1 parent ae3ce79
@erh erh authored
Showing with 48 additions and 1 deletion.
  1. +23 −0 jstests/eval4.js
  2. +25 −1 scripting/sm_db.cpp
View
23 jstests/eval4.js
@@ -0,0 +1,23 @@
+
+t = db.eval4;
+t.drop();
+
+t.save( { a : 1 } );
+t.save( { a : 2 } );
+t.save( { a : 3 } );
+
+assert.eq( 3 , t.count() , "A" );
+
+function f( x ){
+ db.eval4.remove( { a : x } );
+}
+
+f( 2 );
+assert.eq( 2 , t.count() , "B" );
+
+db.eval( f , 2 );
+assert.eq( 2 , t.count() , "C" );
+
+db.eval( f , 3 );
+assert.eq( 1 , t.count() , "D" );
+
View
26 scripting/sm_db.cpp
@@ -176,7 +176,7 @@ namespace mongo {
DBClientConnection * conn = (DBClientConnection*)JS_GetPrivate( cx , obj );
uassert( "no connection!" , conn );
-
+
Convertor c( cx );
string ns = c.toString( argv[0] );
@@ -194,10 +194,34 @@ namespace mongo {
}
}
+ JSBool mongo_remove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){
+ uassert( "mongo_remove needs 2 arguments" , argc == 2 );
+ uassert( "2nd param to insert has to be an object" , JSVAL_IS_OBJECT( argv[1] ) );
+
+ DBClientConnection * conn = (DBClientConnection*)JS_GetPrivate( cx , obj );
+ uassert( "no connection!" , conn );
+
+ Convertor c( cx );
+
+ string ns = c.toString( argv[0] );
+ BSONObj o = c.toObject( argv[1] );
+
+ try {
+ conn->remove( ns , o );
+ return JS_TRUE;
+ }
+ catch ( ... ){
+ JS_ReportError( cx , "error doing remove" );
+ return JS_FALSE;
+ }
+
+ }
+
JSFunctionSpec mongo_functions[] = {
{ "find" , mongo_find , 0 , 0 , JSPROP_READONLY | JSPROP_PERMANENT } ,
{ "update" , mongo_update , 0 , 0 , JSPROP_READONLY | JSPROP_PERMANENT } ,
{ "insert" , mongo_insert , 0 , 0 , JSPROP_READONLY | JSPROP_PERMANENT } ,
+ { "remove" , mongo_remove , 0 , 0 , JSPROP_READONLY | JSPROP_PERMANENT } ,
{ 0 }
};
Please sign in to comment.
Something went wrong with that request. Please try again.