I am trying to return an array of results using Mongoose
and mongoDB
in Node.js
.
I have something like this to match every header that starts with za
for example:
Model.aggregate(
{ $project: { firstLetter : { $substr : ["$header", 0, 2] }}},
{ $match: { firstLetter : 'za' }},
{ $limit: 40 }
);
But when I assign the result to a variable it is just an Aggregate
object that I cannot identify what to do with.
Mongoose docs state:
The documents returned are plain javascript objects, not mongoose documents (since any shape of document can be returned).
Why am I not getting the results?