次のドキュメント構造があります。
{
"_id" : "20120725/foobar/song/test-pg3-long-title-here-test-lorem-ipsum-dolor-lo",
"live_daily_count" : 4,
"metacontent" : { "date" : "20120725",
"live_daily_statable_slug" : "test-pg3-long-title-here-test-lorem-ipsum-dolor-lo",
"live_daily_statable_title" : "test pg3 long title here test lorem ipsum dolor lorem ipsume dolor long description here msam dfam sdfm asfa sfasfas df as f as fas f sa f",
"live_daily_statable_type" : "Song",
"url" : "foobar/songs/test-pg3-long-title-here-test-lorem-ipsum-dolor-lo",
"user_slug" : "foobar" },
"visits" : [
{ "country_name" : "UK",
"iso_two_letter_country_code" : "UK",
"referer" : "http://localhost:3000/",
"minute" : 1121,
"token_id" : "13432416893tlfsmmgh" },
{ "country_name" : "UK",
"iso_two_letter_country_code" : "UK",
"referer" : "http://localhost:3000/",
"minute" : 1281,
"token_id" : "13432512733xcqhhrqs" },
{ "country_name" : "UK",
"iso_two_letter_country_code" : "UK",
"referer" : "http://localhost:3000/",
"minute" : 1285,
"token_id" : "13432515303rwiaczcx" },
{ "country_name" : "UK",
"iso_two_letter_country_code" : "UK",
"referer" : "http://localhost:3000/",
"minute" : 1288,
"token_id" : "13432517303eusgjcgz" }
]
}
訪問を見つけて 1234token_id
13432515303rwiaczcx
に更新するにはどうすればよいですか?minute
Aggregation Framework (以下のコード) を使用して配列内の項目を取得できfind
ますが、更新するにはどうすればよいですか?
connection = Mongo::Connection.new
database = conn['foobar_development']
query = {
aggregate: 'live_daily_stats',
pipeline: [
{ '$project' => {
:visits => 1,
} },
{ '$unwind' => '$visits' },
{ '$match' => { 'visits.token_id' => '13432515303rwiaczcx' } },
]
}
visit = database.command(query)['result'][0]
どちらが返されますか:
{
"_id" => "20120725/foobar/song/test-pg3-long-title-here-test-lorem-ipsum-dolor-lo",
"visits" => {
"country_name" => "UK",
"iso_two_letter_country_code" => "UK",
"referer" => "http://localhost:3000/",
"minute" => 1285,
"token_id" => "13432515303rwiaczcx"
}
}