feathers-reactive
feathers-reactive copied to clipboard
$or filter doesn't work on watch/subscribe
I am using feathers-reactive,
to get some data from a service and I subscribe to the result. When someone invites the user or he invites someone he should receive the updated data.
It does work when I specify the user_id in the query, but if I use a $or he starts to receive updates from all users all over the app
this.app
.service("friends")
.watch()
.find({
query: {
$or: [{ user_id: user.id }, { friend_id: user.id }] // this doesn't work
// user_id: user.id // this work
}
})
.subscribe(friends => console.log(friends));
Expected behavior
It should respect the filter
Actual behavior
It completely ignores the filter when using a $or
More context
I am posting a simple object like this using postman:
{
"user_id": 1,
"friend_id": 2,
"accepted": true
}
workaround
The thing I did to workaround was using channels to only publish the data if the user is in one of the fields:
// app.on("login", (authResult, { connection }) => {...
app.channel(`friends/${connection.user.id}`).join(connection);
//publish
app.service("friends").publish(data => {
return [
app.channel(`friends/${data.user_id}`),
app.channel(`friends/${data.friend_id}`)
];
});
Has this been resolved and forgotten or is it still present?