You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems to me, that this way we'll override the data each time, when the same racer took part in the different race. So, our array field races, embedded in racer always will consist of one element.
I think it should be another way: one racer can take part in many races, so we shouldn't override the races[] data, but do PUSH data to array or something like that.
Am I right?
The text was updated successfully, but these errors were encountered:
You are correct in your assertions about the over-write. The solution was
limited to the test data -- which was formed from a single race.
The goal was to re-share the collections to allow for multiple races,
demonstrate migration of the database to a new (virtual) schema, and the
use of a few MongoDB and Ruby commands along the way. To make your
correction -- we could need to adjust our initial query to group all
results by racer, leverage the aggregation framework to form the re-shaped
document , and use $addToSet for the races as you suggest. If you make that
augmentation, we can add that as a footnote to the assignment step.
Nice observation. If you would like to discuss this more, please create a
newsgroup POST in the week#2 forum since that is focused at MongoDB and
this location reaches a much broader audience.
jim
On Fri, Jul 22, 2016 at 12:08 PM, Koniushenko [email protected]
wrote:
So, we create a new Racer and insert the Race as the first element
within an array within Racer called races
races.find(:name=>{:$exists=>true}).each do |r|
result=racers.update_one({:name=>r[:name]},
{:name=>r[:name],
It seems to me, that this way we'll override the data each time, when the
same racer took part in the different race. So, our array field races,
embedded in racer always will consist of one element.
I think it should be another way: one racer can take part in many races,
so we shouldn't override the races[] data, but do PUSH to array or
something.
Am I right?
So, we create a new Racer and insert the Race as the first element within an array within Racer called races
races.find(:name=>{:$exists=>true}).each do |r|
result=racers.update_one({:name=>r[:name]},
{:name=>r[:name],
:races=>[
{:_id=>r[:_id],
:number=>r[:number],
:group=>r[:group],
:time=>r[:time]}
]}, {:upsert=>true})
It seems to me, that this way we'll override the data each time, when the same racer took part in the different race. So, our array field races, embedded in racer always will consist of one element.
I think it should be another way: one racer can take part in many races, so we shouldn't override the races[] data, but do PUSH data to array or something like that.
Am I right?
The text was updated successfully, but these errors were encountered: