1

I have document in mongodb 2.6.11 including array of string i.e.

{ cpu: [ '0', '2', '4', '0', '0', '2', '0', '4', '0' ],
 con: [ '232', '2396', '17082', '339', '5', '1738', '503', '4', '0' ] }

How do I convert them to numbers without saving in actual collection so I can use them in $project (aggregation) and later use in $group to calculate $avg?

db.checkpointstest3.aggregate([
    {$unwind: "$cpu"}])

I have correct $group , but it works on numbers not strings

1 Answer 1

2

Currently the aggregation pipeline does not allow for type conversion, see this JIRA ticket. If changing the type of your field is not an option, you either have to fall back on a map reduce query or write your own aggregation using forEach.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.