For my test application, I store articles and comments using this schema:
var commentSchema = new mongoose.Schema({
author: String,
text: String,
created: Date
});
var articleSchema = new mongoose.Schema({
title: String,
text: String,
comments: [commentSchema]
});
Now, I’m trying to get all the comments (which are only stored as sub-documents in the articles) posted after a certain date. Additionally, I only want the text
field, not the author
one. This would be equivalent to: Comment.find({created: {$gte: date}}, "text")
but since comments are not stored in their own data store, this would not work.
I haven't used mongoose, so this solution assumes that the subdocuments are the full documents and not just an array of _ids