I'm clearly not understanding the aggregate function in mongoose. I'm trying to query the productCode field and return all of the products. The code below returns the error;
Product.aggregate(...).search is not a function.
What am I doing wrong here? I'm using mongoose.
products = await Product.aggregate().search({
text: {
query: 'text_supplied',
path: 'productCode'
}
});
Update Date
The text in the query comes from an input field. I want to return all the documents from the product collection that contain the text I pass from the input field. This is for an autocomplete dropdown on the client-side. For instance.
Text from input field: '1';
Mongodb Collection: Products
[
{
productCode: '1A'
},
{
productCode: 'C1'
},
{
productCode: 'C2'
}
];
In this scenario, I want to return every product that contains '1'. There for it return '1A' and 'C1'