-1

I have a document like this:

{
price = 140.23563
}

How can multiply the price by 100?

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
  • We have $inc operator in mongo, but is there operator like $multiply ? – Alexandr Kondaurov Jul 08 '13 at 14:08
  • see http://docs.mongodb.org/manual/reference/aggregation/multiply/ – jao Jul 08 '13 at 14:11
  • 2
    There's no atomic operator for this. You have to read the doc, perform the multiplication and then update the doc with the result. – JohnnyHK Jul 08 '13 at 14:18
  • 1
    @AlexandrKondaurov You should add your first comment to the question itself. Wether you want to just multiply by 100 or do it atomically makes a big difference. If you add more information the answers you get will be more precise. – Viktor Seifert Jul 08 '13 at 14:29
  • Duplicate of http://stackoverflow.com/questions/8342725/how-to-update-a-field-in-mongodb-using-existing-value – Dan Dascalescu Dec 10 '13 at 16:17

1 Answers1

3

As of the release notes from upcoming Mongo 2.6 you would be able to use the new $mul operator. It would multiply the value of the field by the number with the following syntax.

{
  field: { $mul: <number> }
}

P.S. keep in mind that 2.6 is not released right now, but will be really soon. You can use experimental 2.5.x instead right now.

Salvador Dali
  • 214,103
  • 147
  • 703
  • 753