
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
MongoDB divide aggregation operator?
You can use aggregate framework for this. Let us first create a collection with documents −
>db.aggregationOperatorDemo.insertOne({"FirstValue":392883,"SecondValue":10000000000}); { "acknowledged" : true, "insertedId" : ObjectId("5cd541452cba06f46efe9f01") }
Following is the query to display all documents from a collection with the help of find() method −
> db.aggregationOperatorDemo.find().pretty();
This will produce the following output −
{ "_id" : ObjectId("5cd541452cba06f46efe9f01"), "FirstValue" : 392883, "SecondValue" : 10000000000 }
Following is the query to use divide aggregation operator −
> db.aggregationOperatorDemo.aggregate([ ... { "$project": { "Value": { "$divide": ["$FirstValue", "$SecondValue"] } } } ... ]);
This will produce the following output −
{ "_id" : ObjectId("5cd541452cba06f46efe9f01"), "Value" : 0.0000392883 }
- Related Articles
- MongoDB aggregation and projection?
- Perform aggregation sort in MongoDB?
- MongoDB aggregation with multiple keys
- Aggregation in MongoDB for nested documents?
- Perform min/max with MongoDB aggregation
- MongoDB aggregation with equality inside array?
- MongoDB aggregation framework match OR is possible?
- Get Absolute value with MongoDB aggregation framework?
- Match between fields in MongoDB aggregation framework?
- How to use $ifNull with MongoDB aggregation?
- MongoDB Aggregation to slice array inside array
- MongoDB query to replace value with aggregation?
- Conditional $first in MongoDB aggregation ignoring NULL?
- MongoDB aggregation framework with group query example?
- Count by multiple fields with MongoDB aggregation

Advertisements