私は自分のマイクロブログアプリのユーザー間の「友達」関係をモデル化しています。これは次のようになります。
user.jsファイル内
var db = require('mongoose')
, Schema = db.Schema
, ObjectId=Schema.ObjectId;
var userSchema = new Schema({
    name:{firstname:String,surname:String},
    birthdate:String,
    email:String,
    posts: [new Schema({
        timestamp:Date,
        post:{type: ObjectId, ref: 'Post'}
    })],
    friends: [new Schema({
        friend: {type:ObjectId, ref:'User'}
    })]
});
module.exports = db.model('User', userSchema);
post.jsファイル内
var db = require('mongoose')
  , Schema = db.Schema,
  ObjectId=Schema.ObjectId;
var postSchema = new Schema({   
        title:String,
        content:String,
});
module.exports = db.model('Post', eventSchema);
私が達成したいのは、現在のユーザーの友達全員に、埋め込まれたドキュメントの投稿配列を既に入力してもらうことです。私は不器用にこの関数を試しました:
function getUserFriendsPost(req, res) {
    var count = 0;
    var output = new Array();
    User.findOne({
        _id: req.params.id
    }, function(err, user) {
        for (var i = 0; i < user.friends.length; i++) {
            User.findOne({
                _id: user.friends[i].friend
            }).populate('posts.post').exec(function(err, post) {
                output.push(post);
                count++;
                if (count==user.friends.length) {
                    res.send(output);
                }
            });
        }
    });
}
代わりに、friends配列が正しく返されますが、投稿の要素の値がnullの場合は、次のようになります。
[
    {
        "_id": "4fd5e5f3e45fd10100000004",
        "birthdate": "11/11/1911",
        "email": "blablabla@gmail.com",
        "friends": [],
        "posts": [
            {
                "timestamp": "2012-04-12T16:47:14.576Z",
                "post": null,
                "_id": "4f870712c488cf0100000081"
            },
            {
                "timestamp": "2012-04-12T16:48:42.282Z",
                "post": null,
                "_id": "4f87076ac488cf01000000a3"
            },
            {
                "timestamp": "2012-04-12T16:56:26.062Z",
                "post": null,
                "_id": "4f87093ac488cf0100000117"
            }
        "name": {
            "firstname": "John",
            "surname": "Doe"
        }
    }
]
インポピュレートメカニズムを見落としているものはありますか、それとも別のアプローチで進める必要がありますか?ありがとうございました