T
T
Tenkoff2010-10-15 02:05:43
MongoDB
Tenkoff, 2010-10-15 02:05:43

Calling Stored JavaScript Functions in MongoDB from PHP

We have a function saved in db.system.js with the name AutoID From the console, everything works fine But I still don’t understand how to call this miracle in PHP, can someone explain / show?

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;
}
}



db.eval("AutoID('Users',{'name':'Tenkoff'})");

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tenkoff, 2010-10-15
@Tenkoff

Taki found the answer if anyone is interested pastie.org/1222477

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question