0
私は、モバイルアプリのためのREST APIを開発しています。これは、モデルの一部である私はマングース - 外部キー参照の設定プレゼンテーション
var UserSchema = new Schema(
{
email :
{
type : String,
unique : true
},
login_type : String,
username :
{
type : String,
index : true
},
password : String
}
を使用していると私は参照
としてスキーマを投稿するユーザーのOIDを追加しましたvar PostSchema = new Schema(
{
author : {type : Schema.Types.ObjectId, ref : "User"},
board_id : {type : Schema.Types.ObjectId, ref : "Board"},
regDate : Number,
lastModDate : Number,
title : String,
content : String,
}
したがって、投稿はユーザーコレクションを参照して投稿したユーザーのusername
になることがあります。だから私はユーザーのユーザー名を取得したい、他は必要ありません。 このため、私は以下を使用しました。
var query = Post.find({"regDate" :{$lte : before}},
{
_id : 1,
title : 1,
"author.username" : 1,
regDate : 1
})
しかし、マングースはそれを無視した"author.username"
。どうすれば私はちょうどauthor
のユーザー名を取得できますか?