https://github.com/muhammadfarooq85/mongodb-arthematic-operators
This repository is about how to use Arthematic operators in mongoDb.
https://github.com/muhammadfarooq85/mongodb-arthematic-operators
database mongodb mongoose nosql
Last synced: 8 months ago
JSON representation
This repository is about how to use Arthematic operators in mongoDb.
- Host: GitHub
- URL: https://github.com/muhammadfarooq85/mongodb-arthematic-operators
- Owner: muhammadfarooq85
- Created: 2024-11-10T13:08:57.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-15T05:26:26.000Z (over 1 year ago)
- Last Synced: 2025-03-15T13:37:16.740Z (over 1 year ago)
- Topics: database, mongodb, mongoose, nosql
- Homepage:
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MongoDb-Arthimatic-Operators
### What are Arthimatic operators in MongoDB?
#### In MongoDB, arithmetic operators are used to perform mathematical operations on data within aggregation pipelines.
### 1) `add`
#### Adds numbers or concatenates strings.
```
db.collection.aggregate([
{
$project: {
newPrice: {
$add: ["$price", 100]
}
}
}
])
```
### 2) `substract`
#### Subtracts one number from another.
```
db.collection.aggregate([
{
$project: {
newPrice: {
$subtract: ["$price", 2]
}
}
}
])
```
### 3) `substract`
#### Subtracts one number from another.
```
db.collection.aggregate([
{
$project: {
newPrice: {
$subtract: ["$price", 2]
}
}
}
])
```
### 4) `multiply`
#### Multiplies numbers together.
```
db.collection.aggregate([
{
$project: {
newPrice: {
$multiply: ["$price", 2]
}
}
}
])
```
### 5) `mod`
#### Returns the remainder of a division operation.
```
db.collection.aggregate([
{
$project: {
newPrice: {
$mod: ["$price", 2]
}
}
}
])
```
### 6) `abs`
#### Returns the absolute value of a number (ignores negative signs).
```
db.collection.aggregate([
{
$project: {
newPrice: {
$abs: ["$price"]
}
}
}
])
```
### 7) `ceil`
#### Rounds a number up to the nearest integer.
```
db.collection.aggregate([
{
$project: {
newPrice: {
$ceil: ["$price"]
}
}
}
])
```
### 8) `floor`
#### Rounds a number up to the nearest integer.
```
db.collection.aggregate([
{
$project: {
newPrice: {
$floor:["$price"]
}
}
}
])
```
### 9) `round`
#### Rounds a number to a specified decimal place.
```
db.collection.aggregate([
{
$project: {
newPrice: {
$round:["$price"]
}
}
}
])
```
### 10) `sqrt`
#### Returns the square root of a number.
```
db.collection.aggregate([
{
$project: {
newPrice: {
$sqrt:["$price"]
}
}
}
])
```
### 11) `pow`
#### Raises a number to a specified exponent (base^exponent).
```
db.collection.aggregate([
{
$project: {
newPrice: {
$pow:[ "$base", 2 ] // Square the value of base
}
}
}
])
```