Hmm, this sounds promising. Trying to experiment with it to replace some in-code search processes we have that are getting a bit slow as our collection grows.
For some reason though, I keep getting an error:
MongoError: Unrecognized pipeline stage name: '$search'
I created a simple collection called Notifications for this test, with a single field: ‘title’ and added some dummy documents to it.
The rawCollection/aggregate part seems to be working okay because the below code returns the single matched document:
try {
const res = await Notifications.rawCollection()
.aggregate([
{
$match: {
_id: 'EAMo8wdqMzWKN96da',
},
},
])
.toArray();
console.log(res); // Single document returned and logged
} catch (err) {
console.error(err);
}
I’ve set up a search index on the ‘title’ field via the Atlas UI as per the tutorial instructions. This below code, however bring up the mentioned error.
try {
const res = await Notifications.rawCollection()
.aggregate([
{
$search: {
text: {
query: 'event',
path: 'title',
},
},
},
])
.toArray();
console.log(res);
} catch (err) {
console.error(err); // MongoError: Unrecognized pipeline stage name: '$search'
}
};
The db is running version 4.2, and the index is building successfully.
Have I missed anything obvious here?
Edit - Would this be a case of certain outdated packages? If so, which ones? (I’m on Meteor 1.11 - so the drivers should have support for Mongo version 4.2).