Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/styllloz/public_html/qa-include/qa-base.php on line 1175

Warning: session_start(): Cannot start session when headers already sent in /home/styllloz/public_html/qa-include/app/users.php on line 162

Warning: Cannot modify header information - headers already sent by (output started at /home/styllloz/public_html/qa-include/qa-base.php:1175) in /home/styllloz/public_html/qa-include/app/users.php on line 1267

Warning: Cannot modify header information - headers already sent by (output started at /home/styllloz/public_html/qa-include/qa-base.php:1175) in /home/styllloz/public_html/qa-include/app/page.php on line 356
Calling stored JavaScript function in MongoDB from PHP - code-flow.club | Q&A

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
8 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 | 8 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
35,181 users