Skip to content

$toBool

Converts a value to a boolean using MongoDB’s truthiness rules.

Syntax

{ "$toBool": <expression> }

Example

Input

{ "flag": "true" }

Stage

{ "$project": { "asBoolean": { "$toBool": "$flag" } } }

Output

{ "asBoolean": true }