Adrian Genaid
Adrian Genaid

Reputation: 436

meteor collection hooks: get context of $set operation on field in array

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")?

Upvotes: 0

Views: 161

Answers (1)

Michel Floyd
Michel Floyd

Reputation: 20246

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.

Upvotes: 1

Related Questions