How to get Data from MongoDb using mongoose?

后端 未结 3 1394
温柔的废话
温柔的废话 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:47

    first compile just one model with the schema as an argument

    var adminLogin = mongoose.model('adminLogin', adminLogin);

    in your code adminLogin does not exist, adminLoginModel does;

    after that ,instead to

    adminLogin.find({}, function(err, data){
            console.log(">>>> " + data );
        });
    

    try this

    adminLogin.find(function (err, adminLogins) {
      if (err) return console.error(err);
      console.log(adminLogins);
    

    is important the "s" because mongo use the plural of the model to name the collection, sorry for my english...

提交回复
热议问题