search

Home  >  Q&A  >  body text

MongoDB根据id查询问题

文章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_leeringa_lee2767 days ago561

reply all(0)I'll reply

No reply
  • Cancelreply