Friends.update: updates the wrong one (the same everytime)

personId2 gets the right ID

client

 approveperson: (fr2) => {

                var personId = fr2.id1;
                
                const confirm = window.confirm('Do you approve this user?');
                if (confirm) {
                    console.log(personId);
                Meteor.call('approveFriends', personId);
                fr2.id1 = "";
                }  
            return false;
            },

server


    pullwaitingFriends(personId2) {
      Friends.update(
        { _id: Meteor.userId(), "friends.id1": personId2, "friends.id2": Meteor.userId() }, 
        
        { $set: { "friends.$.status":3 }  } );
    
    
        Friends.update(
          { _id: personId2, "friends.id1": Meteor.userId(), "friends.id2": personId2 }, 
          
          { $set: { "friends.$.status":3 }  } ); 
    
        },

Do you happen to have a repo that I can look at to try to figure this out?

no sorry, not for this.

{
    "_id" : "FXsCRBoPveGN6XvbJ",
    "friends" : [ 
        {
            "id1" : "9bgkdMgj9RFR9hGwt",
            "id2" : "FXsCRBoPveGN6XvbJ",
            "status" : 0
        }, 
        {
            "id1" : "3D5sGHGSWHrmTKc4t",
            "id2" : "FXsCRBoPveGN6XvbJ",
            "status" : 1
        }, 
        {
            "id1" : "Nt4ZTwqAqKfNo3avi",
            "id2" : "FXsCRBoPveGN6XvbJ",
            "status" : 1
        }, 
        {
            "id1" : "NNRJDiorePPoNTDSL",
            "id2" : "FXsCRBoPveGN6XvbJ",
            "status" : 1
        }, 
        {
            "id1" : "8YBhc3AeKbfHaoNJ9",
            "id2" : "FXsCRBoPveGN6XvbJ",
            "status" : 0
        }, 
        {
            "id1" : "sQEAn5HiCtEnWXHPs",
            "id2" : "FXsCRBoPveGN6XvbJ",
            "status" : 0
        }
    ]
}

Have you taken the time to check out my socialize:friendships package? I’m spent hundreds of hours designing the package, taking into consideration security, usability, and data architecture best practices that don’t fight the way that Meteor’s data system works.

Using the package means that you don’t have to spend that same amount to time. You can get on with the rest of your app knowing that the friends part is taken care of.

If I have seen further it is by standing on ye sholders of Giants

1 Like

have to deliver a beta for a customer tomorrow, and are almost finished with a simple contacts page. I will tjeck out your package ass soon as possible, but for now i have to use what I have.

look at you other thread at Can an mongodb update and $set look like this?

The final code that work:

approveFriends: function(personId1) {
        let meteorUser = Meteor.userId();
        
        Friends.update(
          {friends: {$elemMatch: {id1: personId1, id2: meteorUser}}},
         { $set: {"friends.$.status": 2} } 

        );

        Friends.update(
          {friends: {$elemMatch: {id1: meteorUser, id2: personId1}}},
          { $set: {"friends.$.status" : 2} }

        );
      }