sailsjs use mongodb without ORM

后端 未结 2 1638
旧时难觅i
旧时难觅i 2021-01-28 12:47

I want to use mongodb with sails but without any ORM. So below is my service to connect mongodb.
Service:

//DbService.js

    const MongoClient = require(\'m         


        
2条回答
  •  清酒与你
    2021-01-28 13:22

    As you can see in docs MongoClient.connect() doesn't return Promise object. Instead of this use callback function

    module.exports = {
      db:function(){
        var connect = MongoClient.connect("mongodb:***********", function (err, database) {
          //...
          }  
        });  
      }
    }
    

    btw. Your call DbService.db function in controller will also fail, cuz your service function also doesn't return Promise

    Before you go on, read something about Promises and callback functions

提交回复
热议问题