Hi,
Could someone please explain to me (or show an example) of how to use a Meteor idObject in an aggregate to match.
I sounds stupid but i cannot find a answer to this question.
Here is an example of what I have tried without success
Hi @paulishca,
Sorry about the delay, I tried to email you but it did not work.
Any help you could give me would be greatly appreciated
Thanks again for reaching out
That doesn’t look like a valid command, Meteor’s Mongo.Collection class doesn’t have aggregate method. You can access native MongoDB Node.js driver’s async aggregate method with await Projects.rawCollection().aggregate([...]).toArray();
What type does employerId have?
I assume it’s a string, but in the actual DB it’s an ObjectId, right?
If so, then you either need to: import { MongoInternals } from 'meteor/mongo';
and use it: new MongoInternals.NpmModule.ObjectID(employerId)
or you can install native MongoDB Node.js driver to your app with meteor npm i mongodb@4.15.0, import ObjectId from there: import { ObjectId } from 'mongodb';
and use it: new ObjectId(employerId)
@paulishca
Thank you very much for your offer but I manage to get it going.
My biggest issue was to match the objectId from Meteor and dbar got me going with the MongoInternals import.
Thanks again for helping