2017-04-27 8 views
0

次のように私は何文書内でのみサブ文書を照会して入力する方法はありますか?

queryaggregateWithProject: function (model, matchedCond, prjCond) { 
      return new Promise(function (resolve, reject) { 
       model.aggregate([ 
        {$match: matchedCond}, 
        {$project: prjCond} 
       ], function (error, data) { 
        if (error) 
         reject(error); 
        resolve(data); 
       }); 
      }) 
     } 

、私は今、次のように私のヘルパークラスがあるFROMUSERユーザーID「233232」
を持っているだけレビューを照会し、移入したい enter image description here

、コレクションを持っていますmatchedCondとprojCondのために渡すべきですか?

スキーマ

module.exports = function() { 
    var model = null; 
    var modelName = '_purchase'; 
    try { 
     model = dbService.getModel(modelName); 
    } catch (error) {  

     var userSchema = dbService.createEntityDef({ 
      userId: { 
       type: String 
      },    
      urlPicture: { 
       type: String 
      } 
     }); 
     var reviewSchema = dbService.createEntityDef({ 
      fromUser: userSchema, 
      toUser: userSchema, 
      rating: { 
       type: Number 
      }, 
      comment: { 
       type: String 
      } 


     }) 


     var purchaseSchema = { 
      _id: { 
       type: dbService.getPrimaryKeyType(), 
       index: true 
      }, 
      purchaseId: { 
       type: String 
      },   
      reviews: [reviewSchema] 

     }; 
     model = dbService.createModel(modelName, purchaseSchema, { 
      name: 'text' 
     }, modelName); 
    } 

    return model; 
}; 
+0

スキーマ定義ファイルを貼り付けることはできますか? – ifiok

+0

@ifiokにスキーマファイル –

答えて

1

あなたmatchedCond

{ fromUser.userid : "youruserid" } 

あなたprojCond

{ document: "$$ROOT" } 

は、すべてのプロパティを持つオブジェクトを返します。

+0

が追加されました。何も返されません –

+0

reviews.fromUser.useridにするべきではありませんか? –

+0

あなたのメールIDは何ですか?私はmongoのクエリでいくつかのクエリを持っています。必要なrのヘルプ –

関連する問題