Yup, this is on Atlas. I confirmed that all the settings on Atlas are correct by setting up a stand-alone node.js app and running the same code using the native node mongo drivers.
So this code works and returns the results as expected:
const MongoClient = require('mongodb').MongoClient;
const uri = <MongoURL>
const client = new MongoClient(uri, { useNewUrlParser: true });
client.connect(async (err) => {
try {
const res = await client
.db('meteor')
.collection('notifications')
.aggregate([
{
$search: {
text: {
query: 'event',
path: 'title',
},
},
},
])
.toArray();
console.log(res); // Logs a list of search result documents
console.log(`${res.length} results`);
} catch (error) {
console.error(error);
}
client.close();
});
I tried to mimic a workaround by using the mongo client within the Meteor server:
import mongodb from 'mongodb';
...
const client = new mongodb.MongoClient(uri, { useNewUrlParser: true }); // Error: <rejected> TypeError: MongoClient is not a constructor
Haven’t figured out what/why that isn’t working because I was under the impression that Meteor ships with the native node mongodb driver. @mullojo and @marklynch got this working though so the fault must be in my Meteor code somewhere.