Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<MongoDB\BSON\Decimal128::__toStringMongoDB\BSON\Javascript::__construct>
^MongoDB\BSONLast updated: Mon, 26 Oct 2026

The MongoDB\BSON\Javascript class

(mongodb >=1.0.0)

Introduction

BSON type for Javascript code. An optional scope document may be specified that maps identifiers to values and defines the scope in which the code should be evaluated by the server.

Note:

This BSON type is mainly used when executing database commands that take a Javascript function as a parameter, such as » mapReduce.

Class synopsis

final class MongoDB\BSON\Javascript implements MongoDB\BSON\JavascriptInterface, MongoDB\BSON\Type, JsonSerializable, Stringable {
/* Methods */
final public function __construct(string $code, array|object|null $scope = null)
final public function getCode(): string
final public function getScope(): ?object
final public function jsonSerialize(): mixed
final public function __toString(): string
}

Changelog

Version Description
PECL mongodb 2.0.0 This class no longer implements the Serializable interface.
PECL mongodb 1.12.0 Implements Stringable for PHP 8.0+.
PECL mongodb 1.3.0 Implements MongoDB\BSON\JavascriptInterface.
PECL mongodb 1.2.0 Implements Serializable and JsonSerializable.

Table of Contents


<MongoDB\BSON\Decimal128::__toStringMongoDB\BSON\Javascript::__construct>
^MongoDB\BSONLast updated: Mon, 26 Oct 2026