nodejs & mongojs, keep getting null for get method with findOne

时间:2018-09-18 20:01:27

标签: node.js mongodb mongojs

here is the code:

var express = require('express');
var router = express.Router();
var mongojs = require('mongojs');
var db = mongojs('mongodb://mike:mike@localhost:27017/mytasklist', ['tasks']);


router.get('/task/:id', function(req, res, next) {
    db.tasks.findOne({ _id: mongojs.ObjectId(req.params.id) }, function(err, task) {
        if (err) {
            res.send(err);
        }
        res.json(task);
    });
});

MongoDB is up and running, I keep getting Null on the screen

a screenshot of the result of Getting All the data.

0 个答案:

没有答案