Contact Form

Name

Email *

Message *

Cari Blog Ini

Mongodb Max Operator

MongoDB - max operator

Overview

The max operator in MongoDB returns the maximum value from documents in a collection. It considers both the value and the type of the field when comparing. The BSON comparison order is used to determine the maximum value.

Syntax

 db.collection.aggregate([     {         $group: {             _id: null,             max_value: { $max: "$field" }         }     } ]) 

Parameters

  • field: The field to find the maximum value for.

Return Value

  • The maximum value from the specified field.

Example

 db.collection.aggregate([     {         $group: {             _id: null,             max_age: { $max: "$age" }         }     } ]) 


Comments