
- 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
Why does my MongoDB group query return always 0 in float conversion? How to fix it?
For float conversion, use parseFloat() in MongoDB. Let us create a collection with documents −
> db.demo523.insertOne({"details":{values:"-0.45"}});{ "acknowledged" : true, "insertedId" : ObjectId("5e89b7efb3fbf26334ef611f") }
Display all documents from a collection with the help of find() method −
> db.demo523.find();
This will produce the following output −
{ "_id" : ObjectId("5e89b7efb3fbf26334ef611f"), "details" : { "values" : "-0.45" } }
Following is the query that does not result 0 in the conversion of float −
>db.getCollection('demo523').find({}).forEach( function(d) ... { d.details.values = parseFloat( d.details.values ) ... db.getCollection('demo523').save(d)} );
Display all documents from a collection with the help of find() method −
> db.demo523.find();
This will produce the following output −
{ "_id" : ObjectId("5e89b7efb3fbf26334ef611f"), "details" : { "values" : -0.45 } }
- Related Articles
- Why SHOW DBS does not show my databases in MongoDB?
- MongoDB query to group duplicate documents
- MongoDB query to group by _id
- Why does ice float in water ?
- MySQL float data field not accepting every float number? How to fix this?
- Group query upon nested object in MongoDB?
- MongoDB query to return only embedded document?
- Return query based on date in MongoDB?
- Why does ball not float in water?
- Is it possible to return a list of specific values from a query in MongoDB?
- Why does a blacksmith heat the metal rim to fix it on a cart wheel?
- MongoDB query to push a computed expression in a $group?
- Sort and Group in one MongoDB aggregation query?
- Is it possible to return a list of specific values from a MongoDB query?
- How can I enhance my select query to make it faster in MySQL?

Advertisements