Reputation: 536
I grab the currently selected mongo document using 'this' inside of a Template.alerts.events function. I then want to check to see if the current document (this) contains a specific field. To be precise, I want to see if it contains the userId which I store there myself previously.
doc {
field1: 'a'
myfield: {
userId1: timestamp
userId2: timestamp
...
}
}
I basically want to see if the current user's userId is in the userId fields of myfield.
I have tried:
var x = this.userId
if(this.myfield.x) {
//do something
}
and I'm wondering whether it is because I need to wrap userId in a string or something, but I can't get the condition to evaluate. I have also tried using object.hasOwnProperty which also didn't work. How can I do this in a non query way?
Upvotes: 0
Views: 48
Reputation: 2252
I'm assuming that you're trying to see if 'x' is a field in the object this.myField
. If so, you have to do something like this: if (this.myfield[this.userId])
. If you're trying to compare x
and this.myfield
, then you need to do if (this.userid == this.myfield)
Upvotes: 2