Skip to content

Instantly share code, notes, and snippets.

@Streemo
Streemo / sendMany.js
Created July 28, 2016 18:41
Instead of doing N findOne operations, do a single find operation. Could add some code to explicitly handle 1 vs. N, but it's cleaner to just use arrays for everything, including single elements.
send(m){
if (m.numbers){
m.numbers.forEach((number)=>{
this._sendSMS(m.text, number);
})
} else {
let sentTo = [];
Devices.find({userId: {$in: m.users}}).forEach((device) => {
const devId = this._sendNotification(device, m.title, m.text, m.data);
devId && sentTo.push(devId)