Rentonie
Rentonie

Reputation: 477

'db.Schema is not a constructor' - NodeJS

I've been working on Koa.js and i'm trying to implement some basic authentication functionality. Unfortunately I can't really understand why my snippet isn't working.

const db = require('mongoose')
const bcrypt  = require('bcrypt')
const SALT_WORK_FACTOR = 10;

const UserSchema = new db.Schema({
  username: { type: String, required: true, index: { unique: true } },
  password: { type: String, required: true }
})

module.exports = db.model("User", UserSchema)

The error i'm getting is

const UserSchema = new db.Schema({
                   ^

TypeError: db.Schema is not a constructor

Most of the errors I've googled are limited to typos, but don't think that's the case here.

edit: btw i'm following these steps

Upvotes: 0

Views: 183

Answers (1)

Rentonie
Rentonie

Reputation: 477

apparently it will work as follows, for any future traveller

const UserSchema = db.Schema = {
  username: { type: String, required: true, index: { unique: true } },
  password: { type: String, required: true }
}

Upvotes: 0

Related Questions