0

The number field in my collection can be either Double or Int, and for now it's always equals 1 or 1.0. So I could use this:

db.getCollection('my_collection').update(
   {number:{$type:"double"}},
   {$set: {number: new NumberInt(1)}},
   {multi:true}
)

But what if I have various values, not only 1.0? How do I update each field in collection if it's Double type?

Thank you in advance.

chazsolo
  • 7,873
  • 1
  • 20
  • 44
anako
  • 125
  • 7
  • 3
    You should definetly decide for one either double or int, but mixing them is bad for usability & performance (thats an assumption) ... – Jonas Wilms Nov 09 '18 at 15:27
  • If it can be both, always use the floating point. But be consistent, don't mix them. If you need an integer visually, just round() or toFixed() it clientside. Or just change the units so you can work with integers all the time. For example, it's way easier to work with money as an integer in dollarcents, instead of as a float in dollars. – Shilly Nov 09 '18 at 15:33

0 Answers0