Pull from sub array?

I have a friends Collection where I want to delete a relation with a button in my Vue app:

But how to remove from a sub array.

this dont work

          Friends.update(
            {"_id": Meteor.userId()} , { $and: [{ "friends.0.id1": Meteor.userId()},{ "friends.0.id2": personId } 
           ]},            
            { "$pull": { "friends": { id1: Meteor.userId() } }}
            )

I get this error code:

Exception while simulating the effect of invoking '/friends/update' errorClass {error: 409, reason: "MinimongoError: Invalid modifier specified $and", details: undefined, message: "MinimongoError: Invalid modifier specified $and [409]", errorType: "Meteor.Error", …}

Using your current logic, probably try

Friends.update(
            { _id: Meteor.userId(),
              $and: [{ "friends.0.id1": Meteor.userId()}, { "friends.0.id2": personId } ]},            
            { $pull: { friends: { id1: Meteor.userId() } } } )

Now I get this error:

allow-deny.js:494 Uncaught errorClass {error: 403, reason: "Not permitted. Untrusted code may only update documents by ID.", details: undefined, message: "Not permitted. Untrusted code may only update documents by ID. [403]", errorType: "Meteor.Error", …}details: undefinederror: 403errorType: "Meteor.Error"message: "Not permitted. Untrusted code may only update documents by ID. [403]"reason: "Not permitted. Untrusted code may only update documents by ID."stack: "Error: Not permitted. Untrusted code may only update documents by ID. [403]↵    at throwIfSelectorIsNotId (http://localhost:3000/packages/allow-deny.js?hash=c9344ef36901e05cbb58a8485e17433dac946bdc:513:11)↵    at _0x19bfx8.(anonymous function)._callMutatorMethod (http://localhost:3000/packages/allow-deny.js?hash=c9344ef36901e05cbb58a8485e17433dac946bdc:440:7)↵    at _0x19bfx8.(anonymous function).update (http://localhost:3000/packages/mongo.js?hash=c4281c0ff989ebee020f59f5a7b0735053cea5f7:695:19)↵    at Object.submitRemovePerson (http://localhost:3000/app/app.js?hash=8103d549683d7a80798490f4bab4dff53bcba7b7:1375:17)↵    at http://localhost:3000/packages/blaze.js?hash=813922cefaf3c9d7388442268c14f87d2dde795f:3774:20↵    at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?hash=813922cefaf3c9d7388442268c14f87d2dde795f:3743:12)↵    at Blaze.View.<anonymous> (http://localhost:3000/packages/blaze.js?hash=813922cefaf3c9d7388442268c14f87d2dde795f:3773:25)↵    at http://localhost:3000/packages/blaze.js?hash=813922cefaf3c9d7388442268c14f87d2dde795f:2616:30↵    at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?hash=813922cefaf3c9d7388442268c14f87d2dde795f:2270:12)↵    at Blaze._DOMRange.<anonymous> (http://localhost:3000/packages/blaze.js?hash=813922cefaf3c9d7388442268c14f87d2dde795f:2615:26)"__proto__: Error
throwIfSelectorIsNotId @ allow-deny.js:494
_callMutatorMethod @ allow-deny.js:420
update @ collection.js:580
submitRemovePerson @ main.js:586
(anonymous) @ blaze.js?hash=813922cefaf3c9d7388442268c14f87d2dde795f:3774
Template._withTemplateInstanceFunc @ blaze.js?hash=813922cefaf3c9d7388442268c14f87d2dde795f:3743
(anonymous) @ blaze.js?hash=813922cefaf3c9d7388442268c14f87d2dde795f:3773
(anonymous) @ blaze.js?hash=813922cefaf3c9d7388442268c14f87d2dde795f:2616
Blaze._withCurrentView @ blaze.js?hash=813922cefaf3c9d7388442268c14f87d2dde795f:2270
(anonymous) @ blaze.js?hash=813922cefaf3c9d7388442268c14f87d2dde795f:2615
(anonymous) @ blaze.js?hash=813922cefaf3c9d7388442268c14f87d2dde795f:862
dispatch @ jquery.js?hash=c57b3cfa0ca9c66400d4456b6f6f1e486ee10aad:4723
elemData.handle @ jquery.js?hash=c57b3cfa0ca9c66400d4456b6f6f1e486ee10aad:4391

That is probably because you are using Meteor.userId() to update to the collection. I didn’t understand why that was so just was rearranging the format of the of update using your current logic. So if you don’t know the _id of the document to update to you should remove it from your selector.

Friends.update(
  { $and: [{ "friends.0.id1": Meteor.userId()}, { "friends.0.id2": personId } ]},            
  { $pull: { friends: { id1: Meteor.userId() } } } )

Thanks for your help townmulti

But is was a stupid mistake from my side

I forgot to put the update in the meteor server:

Meteor.call(‘pullFriends’, personId);

pullFriends(personId) {
    Friends.update(
      { $and: [{ "friends.0.id1": Meteor.userId()}, { "friends.0.id2": personId } ]},            
      { $pull: { friends: { id1: Meteor.userId() } } } ),

      Friends.update(
        { $and: [{ "friends.0.id2": Meteor.userId()}, { "friends.0.id1": personId } ]},            
        { $pull: { friends: { id2: Meteor.userId() } } } )
  }