php中的mongodb自动增量

I am using php and mongodb. I want to autoincreement the id. When i am using this code

db.online.insert({
field_id: "register_id",
nextId: 0
},
{
field_id: "user_id",
nextId: 0
});


function getNextIdOnline(field){
var ret = db.online.findAndModify({
    query: { field_id: field },
    update: { $inc: { nextId: 1 } },
    new: true
});    
return ret.nextId;
}

db.online.insert({
 _id: getNextIdOnline("register_id"),
 userid: "8223456",
 username:"Kumar"
});

It is working as fine in mongodb terminal. I want to call to function in php. when using this code

$mng1 = new MongoDB\Driver\Manager("mongodb://user:pass@localhost:27017/db");
$bulk = new MongoDB\Driver\BulkWrite;
    $proccode = 'getNextIdOnline("register_id")';
$bulk->update(['userid' => $userphone], ['_id' =>  new MongoCode($proccode),'userid' => $userphone, 'username' => $username, 'active_time' => $today], ['upsert' => 'true']);

$mng->executeBulkWrite("db.online", $bulk);

Then it shows the error is

Uncaught Error: Class 'MongoCode' not found.

I got the reference from http://pointbeing.net/weblog/2010/08/getting-started-with-stored-procedures-in-mongodb.html

How can auto increement the field using php? Please help me.

Is there any substitute for mongocode?