Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have int array to update in collection using mongo shell .When I update it actually it stores in double format .

var  array =[1,2,3];     // int array as all elements are int 
                         // Update query where path is the collection field
 db.doc.update({},{$set : {“path”:array}},{ upsert: true });  

Actually it stored:

{
  "_id" : ObjectId("529ae0e70971d81eedf5cb3d"),
  "path" : [1.0, 2.0, 3.0]
}

I am novice to mongo and have to run update query in mongo shell. How to avoid auto double conversion.

share|improve this question
add comment

1 Answer

Mongoshell treats numbers as float by default. So if you want them to be treated as something else, tell this to mongo explicitly. For your case, you have to use NumberInt().

So var array = [NumberInt("1"), NumberInt("2"), NumberInt("3")];

P.S. you might find my another answer (which is similar) helpful as well.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.