How to get Data from MongoDb using mongoose?

后端 未结 3 1375
温柔的废话
温柔的废话 2021-01-11 11:25

I just started learning MongoDB and mongoose. Currently I have the following structure:

database   -> skeletonDatabase
collection -> adminLogin
         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-11 11:51

    Had a problem with injecting it within an express route for my api so I changed it thanks to @elkhrz by first defining the schema and then compiling that one model I want to then pull like so:

    app.get('/lists/stored-api', (req, res) => {
    
        Apis.find(function(err, apis) {
    
            if (err) return console.error(err);
    
            res.send(apis);
    
        });
    
    });
    
    

    I wouldn't send it to the body, I would actually do something else with it especially if you plan on making your API a production based application.

    Run through this problem and read up on possible proper ways of rendering your data: How to Pass Data Between Routes in Express

    Always a good idea to practice safe procedures when handling data.

提交回复
热议问题