that's my model
var schema = new mongoose.Schema({
title: String,
link: String,
gid: Number,
posts: [],
date: { type: Date, default: Date.now },
}, { collection: 'Group' });
var Group = mongoose.model('Group', schema);
I need to get all posts objects from collection by one query.
Using mongoose it should work with the following statement using a projection to return only the posts field (and the _id
field)
Group.find({},{"posts":1} ).exec(callback)
To only get all posts you have to use an aggregation.
Group.aggregate([{$unwind : "$posts"}, {$project: {"post":"$posts", _id:0}}]).exec(callback)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.