Have the function saved in db.system.js by name, AutoID
function (n,o) {
x = db.getCollection(n);
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.getLastErrorObj();
if( err && err.code ) {
if( err.code == 11000 /* dup key */ )
continue;
else
print("unexpected error inserting data:" + tojson(err));
}
break;
}
}
From the console all works fine
db.eval("AutoID('Users',{'name':'Tenkoff'})");
But how to call this miracle in PHP did not understand, can someone explain/show?