MongoDB根据id查询问题
ringa_lee
ringa_lee 2017-04-22 08:56:11
0
0
484

文章Model:

 Post.getOneById = function(_id, callback) {
       ...
      db.collection('posts', function(err, collection){
           collection.findOne({"_id": new ObjectID(_id)},function(err, doc){
                     ....
               }
       }
 }

路由:

app.get('/p/:_id', function(req, res){

   Post.getOneById( req.params._id, function(err, post){
         ...
   }
}

好像这句有问题 {"_id": new ObjectID(_id)}

ringa_lee
ringa_lee

ringa_lee

reply all(0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!