猫鼬用findOne填充返回的空数组

时间:2019-05-01 10:05:52

标签: javascript node.js express mongoose

在尝试填充ID数组后,猫鼬只是返回一个空数组而不是填充的Array。我还尝试使用findById和find方法。

路线正在运行。

在我的控制器文件中:

presentation

在我的路由器文件中:

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "shell",
      "label": "g++ build active file",
      "command": "/usr/bin/g++",
      "args": [
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}",
      ],
      "presentation": {
        "reveal": "silent",
        "panel": "shared"
      },
      "options": {
        "cwd": "${fileDirname}"
      },
    },
    {
      "label": "cpp-run",
      "type": "process",
      "command": "${fileDirname}/${fileBasenameNoExtension}",
      "dependsOn": [
        "g++ build active file"
      ],
      "presentation": {
        "reveal": "always",
        "panel": "shared"
      },
      "options": {
        "cwd": "${fileDirname}"
      },
    },
    {
      "label": "cpp-test",
      "type": "process",
      "command": "rm",
      "args": [
        "${fileDirname}/${fileBasenameNoExtension}"
      ],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "dependsOn": [
        "cpp-run"
      ],
      "presentation": {
        "reveal": "never",
        "panel": "shared"
      },
      "options": {
        "cwd": "${fileDirname}"
      },
    }
  ],
}

餐厅架构:

var Restaurant = require('../../shared/models/restaurant');
var objectID = require('mongodb').ObjectID

exports.get_Restaurant_detail = (req, res, next) => {
    if(objectID.isValid(req.params.id)){
        Restaurant.findOne({"_id": req.params.id})
        .populate("dishes")
        .exec( (err, restaurant) => {
            if(err) return res.send("error");
            res.json(restaurant);
        });
    } else {
        res.status(400).json({"status": "Error"})
    }

}

菜式

//GET detailed information about a specific restaurant
router.get('/restaurants/detail/:id', read_controller.get_Restaurant_detail);

(这些模式位于两个不同的文件中)

0 个答案:

没有答案