2014-08-27 54 views
0

我有視頻模式(水線)高級申請(帆的NodeJS)

視頻

-title 
    -description 
    -matches (array) 
    [0] 
     - MatchTitle 
     - MatchDescription 
    [1] 
     ... 
    [N] 

我如何才能找到其中包含匹配標題爲「ABC」,例如視頻?

我寫的不是最好的解決方案,因爲它是從數據庫retrive所有數據

Video.find({is_html5:true}).done(function(err, videos) { // get all videos 
    async.forEach(videos, function(video, callback) { 
    var isFound = false; 
    async.forEach(video.matches, function(videoMatch, matchCallback) { // get video matches 
     if(videoMatch.gs_id === match.gs_id && !isFound) { 
     match.relatedVideos.push(video.id); 
     isFound = true; 
     } 
     matchCallback(); 
    }, function(err3) { 
     callback(); 
    }); 
    }, function(err2) { 
    cb(); 
    }); 
}, function(err1) { 
    cb(); 
}); 

回答

0

如何使用一些蒙戈的魔術和找到數組項的財產視頻?

Video.find({'matches.matchTitle' : 'ABC'}).exec(...); 

// or using regex (if you want to match a substring) 
Video.find({'matches.matchTitle' : { $regex: /ABC.*/ }}).exec(...); 

這有什麼幫助。