| Use Case | Command | Description |
|---|---|---|
| 🗜️ Create plain JS code | bson_code($js) | Wraps a JavaScript string as BSON code type |
| 🧩 Create JS code with scope | bson_code($js, $scope) | Wraps code along with a scope hashref |
| 📏 Get code length | $code->length | Returns length of the code string |
| 🔄 Convert to extended JSON | $code->TO_JSON | Returns MongoDB extended JSON doc (when BSON_EXTJSON is true); throws error otherwise |
use BSON::Types ':all';
$code = bson_code( $javascript );
$code = bson_code( $javascript, $scope );
undef.
BSON_EXTJSON option is true, returns a hashref compatible with MongoDB's extended JSON
<https://github.com/mongodb/specifications/blob/master/source/extended-json.rst> format, which
represents it as a document as follows:
{"$code" : "<code>"}
{"$code" : "<code>", "$scope" : { ... } }
If the BSON_EXTJSON option is false, an error is thrown, as this value can't otherwise be
represented in JSON.
Generated by phpman v4.9.25-4-g0d844aa · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-07 09:08 @216.73.217.93
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-pro / taotoken.net / www.chedong.com - original format