Update nested hash MongoDB - Ruby -


I am trying to update a hash with a simple value in a mongodibi doctor but it is an array of values Stores.

What do I have:

  {'id': ... 'stream': {"1406481985 (a timestamp)": 35603}}  

What do I need:

  {'id': ... 'stream': {"1406481985 "What I Get:    .. 'Stream': {"1406481985": 35603, "1406481990": [15000]}}  

How did I get there? Update

  view = 15000 time = time.on coll.find_and_modify ({query: {id = & gt; id},: {'$ push' => gt; ; {"Stream. # {Time}" =>, thoughts}},}}  

I have already tried and I 'I do not know what I do?

Daniel niPers is correct - I should also use $ set Are you using a id instead of '_id` perhaps a typo? Edit: Note that generally the dynamic key values ​​are not recommended because they are hard for index and query, within an array there is a stream of the hashes. Consider the structure:

  {'_id': ... 'stream': [{'time': 1406481985, 'idea': 35603}, {'time': 1406481990, Idea ': 15000}]}  

Now you can easily query time and ideas fields.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -