On this page本页内容
The following table lists the input types that can be converted to a boolean:下表列出了可以转换为布尔值的输入类型:
| Boolean | |
| Double | true。false。 |
| Decimal | true。false。 |
| Integer | true。false。 |
| Long | true。false。 |
| ObjectId | true。 |
| String | true。 |
| Date | true。 |
The following table lists some conversion to boolean examples:下表列出了一些转换为布尔值的示例:
{$toBool: false} |
false |
{$toBool: 1.99999} |
true |
{$toBool: NumberDecimal("5")} |
true |
{$toBool: NumberDecimal("0")} |
false |
{$toBool: 100} |
true |
{$toBool: ISODate("2018-03-26T04:38:28.044Z")} |
true |
{$toBool: "false"} |
true |
{$toBool: ""} |
true |
{$toBool: null} |
null |
Create a collection 使用以下文档创建集合orders with the following documents:orders:
The following aggregation operation on the 在查找未发货的订单之前,orders collection converts the shipped to a boolean value before finding the unshipped orders:orders集合上的以下聚合操作将shipped转换为布尔值:
The operation returns the following document: