Skip to content

Instantly share code, notes, and snippets.

@wsmoak
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wsmoak/27e92ea2e5b5bd313155 to your computer and use it in GitHub Desktop.
Save wsmoak/27e92ea2e5b5bd313155 to your computer and use it in GitHub Desktop.
{
"_id": {"$oid": "546396c27e12bd7eab000007"},
"id": "43",
"doe": "3BL",
"buck": "C16",
"birth_date": "2014-10-24 04:00:00 UTC",
"kindled": 2,
"survived": 2,
"weights": [
{
"date": "2014-11-10 05:00:00 UTC",
"data": [
{
"weight": 1.14,
"count": 1,
"id": "A",
"notes": ""
},
{
"weight": 1.1,
"count": 1,
"id": "B",
"notes": ""
}
]
}
]
}
doc = { "weight": 1.2, "count": =, "id": "C", "notes": "another" }
What does adding the doc above to the end of the weights.data array look like ?
litters.update( {id: "43" }, { "$push" => { ??? } } )
Where do I specify the weights.date so that it goes into the right one ?
SOLVED (in Ruby)
litters.update( {:id => params[:id], "weights.date" => date }, { "$push" => { "weights.$.data" => data } } )
Mongo syntax (I think) is:
litters.update( {id: "43", "weights.date": ~the-date~ }, { "$push": { "weights.$.data": doc } } )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment