meteor-easy-search
meteor-easy-search copied to clipboard
Searching in related fields with $lookup
describe how to search in related fields with $lookup.
import { Meteor } from 'meteor/meteor'
export const findRelatedFieldDocuments = Meteor.wrapAsync((data, cb) => {
const {
collection,
from,
localField,
foreignField,
as,
selector,
} = data
collection.rawCollection().aggregate([
{
$lookup: {
from,
localField,
foreignField,
as,
},
},
{ $match: selector },
]).toArray().then(res => cb(null, res)).catch(err => cb(err))
})
Not really performant, but still worth mentioning.