Calling stored JavaScript function in MongoDB from PHP


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
3 views
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?
by | 3 views

1 Answer

0 like 0 dislike
Finally found the answer, if anyone is interested pastie.org/1222477
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
27,217 users