Hi,
I am not 100% sure when to use await inside an async function on the server when using find, findOne, insert and update.
For example is this valid on the server (?):
const someFunc = async args => {
const {color} = args
const carIds = await carsCollection.find({color}).map(car => car._id);
const busIds = await busCollection.find({color}).map(bus => bus._id);
const registrationNumbers = await registrationCollection.find({vehicleId: {$in: [...carIds, ...busIds]}})
return registrationNumbers;
}
or is find/findOne blocking on the server and I can safely do this:
const someFunc = args => {
const {color} = args;
const carIds = carsCollection.find({color}).map(car => car._id);
const busIds = busCollection.find({color}).map(bus => bus._id);
const registrationNumbers = registrationCollection.find({vehicleId: {$in: [...carIds, ...busIds]}})
return registrationNumbers;
}
The meteor documentation states that insert and update are blocking on the server.
Does this mean that I do not need to use await for insert and update?
So on the server it makes no sense to write(?):
const carId = await carCollection.insert({a:1});
Also it makes no sense on the server to write (?):
const carId = await carCollection.update({},{$set{a:2}});
Similarly does this make sense on the server for remove(?):
export const remove = args => {
const {systemId} = args;
const promiseArray = [
Systems.remove(systemId),
Catalogs.remove({systemId}),
Xrefs.remove({systemId}),
Zones.remove({systemId}),
Links.remove({systemId}),
Nodes.remove({systemId}),
UserSettings.remove({systemId})
];
const prom = Promise.all(promiseArray).catch(err => {
throw new Meteor.Error('systems remove err', err);
});
return prom;
};