$exp - Amazon DocumentDB
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

$exp

New from version 4.0

The $exp operator in Amazon DocumentDB allows you to raise the constant e to a given number.

Parameters

  • expression: The expression to evaluate. This can be any valid aggregation expression, including field references, arithmetic operations, and other aggregation stages.

Example (MongoDB Shell)

The following example demonstrates the use of the $exp operator to find all documents where the quantity field is greater than the price field.

Create sample documents

db.items.insertMany([ { item: "canvas", quantity: 4 }, { item: "journal", quantity: 2 } ]);

Query example

db.items.aggregate([ { $project: { "quantityRaised": {$exp: "$quantity"}} } ]);

Output

[ { _id: ObjectId('6920b785311cf98b79d2950d'), quantityRaised: 54.598150033144236 }, { _id: ObjectId('6920b785311cf98b79d2950e'), quantityRaised: 7.38905609893065 } ]

Code examples

To view a code example for using the $exp command, choose the tab for the language that you want to use:

Node.js
const { MongoClient } = require('mongodb'); async function aggregateExp() { const client = await MongoClient.connect('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false'); const db = client.db('test'); const items = db.collection('items'); const result = await items.aggregate([ { $project: { "quantityRaised": {$exp: "$quantity"}} } ]).toArray(); console.log(result); client.close(); } aggregateExp();
Python
from pymongo import MongoClient def aggregate_exp(): client = MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false') db = client.test items = db.items result = list(items.aggregate([ { "$project": { "quantityRaised": {"$exp": "$quantity"}} } ])) print(result) client.close() aggregate_exp()