2017-03-07 70 views
0

我正在使用這個code link。 Datatable已創建,但我如何使用查詢填充方法。作爲根據提供的代碼:在Node js + Mongo DB中使用數據表的填充方法

exports.getDataForDataTable = function getData (request, response) 
{ 
    MyModel.dataTable(request.query, function (err, data) { 
    response.send(data); 
    }); 
}; 
+0

可能重複http://stackoverflow.com/questions/17598712/how-should-i-properly-填入字段use-populate-with-mongoose –

+0

我正在使用數據表,所以我需要語法與數據表。通常填充工作,但它如何與數據表語法工作。 – Anshul

回答

1

添加在request.query對象

exports.getDataForDataTable = function getData (request, response) 
{ 
    request.query.populate = 'Model'; 
    MyModel.dataTable(request.query, function (err, data) { 
    response.send(data); 
}); 
}; 
+0

應用此搜索後,不適用於其他列,它僅適用於第一列。 – Anshul

+0

必須在搜索對象字段中定義字段:['username']您要在其中搜索的字段。你可以conosle.log你request.query對象並粘貼在這裏,所以我可以看到什麼是錯的。 –

+0

條件:{'$和':[{'$或':[{title:{'$ in':[/ 2/i]}}]}]},這個條件只生成 – Anshul

相關問題