Ich verwende Edelstein und Mongoid in Ruby. Ich verbinde tatsächlich die Mongo-Geschichte mit einem Modell namens SocialPost, also kann ich so etwas machen.Erstellen Sie ein Modell Scope mit Hash-Attribut
history = current_user.social_posts.history_tracks
Jetzt muss ich diese ‚Geschichte‘ filtern, mit einem Rahmen oder ein Verfahren, das Filterattribut ‚association_chain‘ aus der Geschichte Tracker-Modell, aber ‚history_tracks‘ Attribute auf diese Weise hergestellt werden:
<HistoryTracker _id: 57bdc1cb65e59325ae000001, created_at: 2016-08-24 15:48:27 UTC, updated_at: 2016-08-24 15:48:27 UTC, association_chain: [{"name"=>"SocialPost", "id"=>BSON::ObjectId('57ac8b0f65e5930944000000')}], modified: {"facebook_likes_count"=>2594213, "tweeter_followers_count"=>0}, original: {}, version: 1, action: "update", scope: "social_post", modifier_id: nil>
Also, wie kann ich eine Suche in meinem HistoryTracker Modell erstellen, die mir erlauben, eine bestimmte Gruppe von ids innerhalb association_chain, so etwas zu suchen:
UPDATE $ elemMatch
#test case multiple social_id: empty result
HistoryTracker.any_in({:association_chain.elem_match => [{name: 'SocialPost', :id.in => social_ids}] })
#test case 1 social_id: match result
HistoryTracker.any_in({:association_chain.elem_match => [{name: 'SocialPost', :id => social_ids.first}] })