Bu fonksiyon db.system.js sakladığınız
function SomeFunc(o) {
x = db.Collection;
while( 1 ) {
var c = x.find({},{_id:1}).sort({_id:-1}).limit(1);
var i = c.hasNext() ? c.next()._id + 1 : 1;
o._id = i;
x.insert(o);
var err = db.getLastHataObj();
if( err && err.code ) {
if( err.code == 11000 /* dup key */ )
continue;
else
print("unexpected error inserting data: " + tojson(err));
}
break;
}
}
PHP
print_r(
$db->execute("SumeFunc(o)", array("name" => "test"))
);
Hata
Array
(
[errno] => -3
[errmsg] => invoke failed: JS Hata: ReferenceHata: o is not defined nofile_a:0
[ok] => 0
)