How to get Data from MongoDb using mongoose?

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

    mongoose by default takes singular model names and pairs them with a collection named with the plural of that, so mongoose is looking in the db for a collection called "adminLogins" which doesn't exist. You can specify your collection name as the 2nd argument when defining your schema:

    var adminLogin = new Schema({
        username: String,
        password: String
    }, {collection: 'adminLogin'});
    

提交回复
热议问题