How do I perform a find query in Mongoose?

前端 未结 1 1359
梦毁少年i
梦毁少年i 2021-02-04 12:03

i have a collection of Ebooks data in mongodb like

{ 
    \"_id\" : ObjectId(\"58b56fe19585b10cd42981d8\"), 
    \"cover_path\" : \"D:\\\\Ebooks\\\\uploads\\\\eb         


        
1条回答
  •  醉梦人生
    2021-02-04 12:52

    Try wrapping your query in curlies, Mongoose expects an object as the query.

    app.get('/ebook?search=',function(req,res){
    var search_key = req.param('search');
        Ebook.find({title: search_key})
           .then(ebooks => res.json(ebooks))
           .catch(err => res.status(404).json({ success: false }));
        });
    

    0 讨论(0)
提交回复
热议问题