MongoDB 提供了不同類型的中使用的算術表達式運算符聚合管道階段和$log10 操作符就是其中之一。這操作員用於查找指定數字的對數基數 10,並以雙精度形式返回結果。
用法:
{ $log10: <number> }
在這裏,數字是一個有效的表達式,直到它解析為一個非負數。
- 如果輸入的值為空,則此運算符將返回空。
 - 如果輸入的值為 NaN,則此運算符將返回 NaN。
 - 如果輸入的值是缺失字段,則此運算符將返回 null。
 
例子:
在以下示例中,我們正在使用:
Database: GeeksforGeeks
Collection:example
Document: two documents that contain the details of the shapes in the form of field-value pairs.

使用 $log10 運算符:
在這個例子中,我們將找到值的對數以 10 為底的方形文檔中的邊字段。
db.example.aggregate([{$match:{name:"Square"}},
... {$project:{logbas10:{$log10:"$side"}}}])

在嵌入的文檔中使用 $log10 運算符:
在這個例子中,我們將找到值的對數以 10 為底測量高度矩形文檔中的字段。
db.example.aggregate([{$match:{name:"Rectangle"}},
... {$project:{logbase10:{$log10:"$measurement.height"}}}])

相關用法
- MongoDB $mul用法及代碼示例
 - MongoDB $rename用法及代碼示例
 - MongoDB $setOnInsert用法及代碼示例
 - MongoDB $ln用法及代碼示例
 - MongoDB $floor用法及代碼示例
 - MongoDB $divide用法及代碼示例
 - MongoDB $add用法及代碼示例
 - MongoDB $ceil用法及代碼示例
 - MongoDB $sqrt用法及代碼示例
 - MongoDB $multiply用法及代碼示例
 - MongoDB $mod用法及代碼示例
 - MongoDB $log用法及代碼示例
 - MongoDB $abs用法及代碼示例
 - MongoDB $strcasecmp用法及代碼示例
 - MongoDB $toLower用法及代碼示例
 
注:本文由純淨天空篩選整理自ankita_saini大神的英文原創作品 MongoDB $log10 Operator。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
