I'm trying to update a hash in a MongoDB doc with a simple value but it store the value in an array. I use the ruby driver for mongo
Code will explain better because my english is bad.
What I have :
{
'id' : ...
'stream' : {
"1406481985(a timestamp)" : 35603
}
}
What I want :
{
'id' : ...
'stream' : {
"1406481985" : 35603,
"1406481990" : 15000
}
}
What I get :
{
'id' : ...
'stream' : {
"1406481985" : 35603,
"1406481990" : [
15000
]
}
}
How did I get there :
views = 15000
time = Time.now
coll.find_and_modify({
query: {:id => id},
update: {'$push' => {"stream.#{time}" => views}},
})
I've already tried with Updating nested document in MongoDB and I can't see what I do wrong