0

I have a collection that contains an array of objects; schema looks like the following:

Boards.attachSchema(new SimpleSchema({
  [...]
  'members.$.userId': {
    type: String,
  },
  'members.$.isActive': {
    type: Boolean,
  },
  [...]

Now I have a collection hook after.update which correctly fires if an update happens on one member of the board.

How would I get the member (or, the userId of the member) on which the update happens (if, as in my case only isActive is changed for the member? The modifier looks like the following in that case:

{"$set":{"members.1.isActive":true,"modifiedAt":"2017-07-27T15:40:19.733Z"}}

Do I have to split the field name to be able to locate the member?

How can I even detect this situation ("a member was activated")?

Adrian Genaid
  • 416
  • 5
  • 17

1 Answers1

1

According to Aldeed, this.docId should be available on the server.

You may also find the matb33:meteor-collection-hooks package useful. It essentially allows you to create database triggers.

Michel Floyd
  • 18,793
  • 4
  • 24
  • 39
  • I don't know if there are other packages for collection hooks, but the mentioned "collection hook after.update" is just such a hook of the matb33:meteor-collection-hooks package. – Adrian Genaid Aug 10 '17 at 12:27
  • 1
    Ah I see, I misunderstood the question, I thought you were trying to get the `memberId` in your schema code itself (for example in an `autoValue`). In `after.update()` the doc itself is available as the second parameter. You should be able to look at `doc.members.1.userId`. It would be way easier to do this in the schema's `autoValue` code. – Michel Floyd Aug 10 '17 at 17:05