coll.save({"_id" => "test", "1" => "a"}) #=> {"_id"=>"test", "1"=>"a"}
coll.update({"_id" => "test"}, {"$set"=>{"1.2" => "b"}}) #=> {"_id"=>"test", "1"=>"a"}
I was expecting that last line would create a new node: {"_id"=>"test", "1"=>{"2"=>"b"}}
or {"_id"=>"test", "1"=>["a",{"2" => "b"}]}
Is it possible to have it create a node that doesn't exist? and to unshift into an array if there's already a key:value pair?
one more:
coll.save({"_id" => "test", "1" => ["a"]}) #=> {"_id"=>"test", "1"=>["a"]}
coll.update({"_id" => "test"}, {"$set"=>{"1" => ["b"]}}) #=> {"_id"=>"test", "1"=>["b"]}
Is it possible to unshift values into arrays, without overwriting them? thus making above:
#=>{"_id"=>"test", "1"=>["a","b"]}
I say this because I have large arrays, and there's a performance overhead if I download the array, and unshift it on Ruby's side.
And with the first question, the documents in the collection have a variety of shapes, and building a when:case method in ruby would be a lot of overhead / work for all the possibilities.
Ruby unshift: http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-unshift
::edit::
$db.serverStatus().version
2.0.2
$gem list
mongo (1.6.2, 1.6.1, 1.5.2)
Exact code:
require 'pp'
require 'mongo'
coll = Mongo::Connection.new.db("test").collection("test")
coll.save({"_id" => "test", "1" => "a"})
pp coll.find_one("_id"=>"test") #=> {"_id"=>"test", "1"=>"a"}
coll.update({"_id" => "test"}, {"$set"=>{"1.2" => "b"}})
#Expect, but does not give: {"_id"=>"test", "1"=>{"2"=>"b"}}
pp coll.find_one("_id"=>"test") #=> {"_id"=>"test", "1"=>"a"}