Closed rnenjoy closed 8 years ago
Your second example is right. Alternately, if you want to check the responses of the removeAll:
messages.findAll({ from: 'bob' }, {from: 'agatha' }).fetch()
.map(messageList => messages.removeAll(messageList))
.subscribe({
next(removedId) { console.log(`id ${removedId} was removed`) },
error(err) { console.error(`Error removing items! ${err}`) },
complete() { console.log('All items removed successfully') },
})
@deontologician Would it fix the example at http://horizon.io/api/collection/#removeall to add a .toArray()
here?
var messageList = messages.findAll({from: "bob"}, {from: "agatha"}).fetch().toArray();
No, .toArray()
still returns an observable, instead of getting [{id:1}, ...]
you'd get [[{id:1}, ...]]
since it's already emitting an array. In this case there's no way around a callback like @rnenjoy does with .subscribe, or by chaining operations like in my example. It's fundamentally an asynchronous operation, and the example is written in a style that requires the results to be available synchronously
Ah right, makes sense. So what you wrote here https://github.com/rethinkdb/horizon-docs/issues/79#issuecomment-225373482 is probably what we should put into the docs?
Yeah, it's effectively the same as @rnenjoy's example, but is more general since it shows how to get the removed ids back out
Hello,
Maybe im doing this the wrong way, but i tried the example:
I couldn't get this working since removeAll expects an object, and messageList seems to be just a snapshot? This is how I made it, but then again, i'm a n00b: