How to change collection name in mongoose.model?

前端 未结 1 880
你的背包
你的背包 2020-12-22 09:14

Am new in Nodejs, Am trying to create user login system with mongoDB and passportjs. Here i want to change collection name.

i r

1条回答
  •  隐瞒了意图╮
    2020-12-22 10:12

    You can use this structure. API structure of mongoose.model is this:

     Mongoose#model(name, [schema], [collection], [skipInit])
    

    which means

     mongoose.model('User', AdminSchema, 'admin'); 
     //Here 3rd argument 'admin': as collection name
    

    You can do with this too

    let AdminSchema = mongoose.Schema({
      username : String,
      password : String.
      ....... 
    }, { collection: 'admin' });
    

    See this link from the Mongoose documentation.

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