【问题标题】:Use Populate method with datatables in Node js + Mongo DB在 Node js + Mongodb 中对数据表使用 Populate 方法
【发布时间】:2017-03-07 19:59:43
【问题描述】:

我正在处理这个code link。数据表已创建,但我如何使用带有查询的填充方法。根据提供的代码:

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

【问题讨论】:

标签: node.js mongodb datatable


【解决方案1】:

在 request.query 对象中添加填充字段

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

【讨论】:

  • 应用后此搜索不适用于其他列,仅适用于第一列。
  • 必须在搜索对象字段中定义字段:要在其中搜索的 ['username']。你能把你的 request.query 对象 conosle.log 并粘贴到这里,这样我就可以看到有什么问题了。
  • 条件:{ '$and': [ { '$or': [ { title: { '$in': [ /2/i ] } } ] } ] },产生这个条件只有
  • 它还必须包含其他列。
  • search: { value: '', regex: 'false' },这是在我控制台查询对象进行搜索时出现的。
猜你喜欢
  • 2017-10-07
  • 2015-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-06
相关资源
最近更新 更多