0

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

Rentonie
  • 477
  • 1
  • 10
  • 25
  • @alexmac `const UserSchema = new (db.Schema)({` provides the same error. I've found a workaround though. – Rentonie Aug 15 '17 at 20:32

1 Answers1

0

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 }
}
Rentonie
  • 477
  • 1
  • 10
  • 25