I am porting an old PHP application from the legacy Mongo DB code to the current mongoDB library version. For invoice generation, I require a sequence. Previously I used:
db.system.js.save(
{
_id: "getNextSequence",
value: function (client, id) {
var ret = db.counter.findAndModify(
{
query: {client: client, id: id},
update: {$inc: {seq: 1}},
new: true
}
);
return ret.seq;
}
});
And from PHP side:
$getNextSequence = new MongoCode("getNextSequence('$client', 'invoices')");
$ret = $this->db->execute($getNextSequence);
$nextId = $ret['retval'];
Unfortunately this is no longer possible as the MongoCode class is no longer around. And frankly, the documentation on MongoDB PHP Library is useless.
Question: How can I either
a) call this Javascript from PHP using the new MongoDB PHP Library or
b) find a different way to increase the sequence and fetch the updated number at the same time