Reputation: 399
This is an example of my Mongoose schema:
mongoose.model('Support', {
createdBy: mongoose.Schema.Types.ObjectId,
title: String,
replies: { type: Array, default: [] }
}
The replies array can contain several objects, to which I'm not interested in the first query, but I do need the length of the array.
Is there a mongoose solution for this problem? Currently I'm just looping through each document.
My code so far:
Support.find({}, function(err, docs) {
if (err) throw err;
async.each(docs, function(doc, next) {
doc.replies = doc.replies.length;
next();
}, function() {
/* Work with the result */
}
});
Upvotes: 3
Views: 2254