node.js - Mongoose model not saving for some reason -


i've create mongoose model , wrote code test if works, tried save model , display of models doesn't log console , model isn't saving.

my testing code:

let user = require('./models/user')(mai); let myuser = new user({   username: 'admin',   email: 'admin@example.com',   password: '123456', });  await myuser.save();  user.find((err, users) => {   if(err) console.log(err);   console.dir(users); }); 

my model:

const mongoose = require('mongoose');  const userschema = mongoose.schema({   user_id: number,   username: string,   email: string,   password: string,   verified: { type: boolean, default: false },   joindate: { type: date, default: date.now },   postcount: { type: number, default: 0 }, });  module.exports = function(mai) {   userschema.plugin(mai.plugin, {     model: 'user',     field: 'user_id',     startat: 1,     incrementby: 1,     unique: true   });   return mongoose.model('user', userschema); } 

and if it's important, mongoose & mai initialization:

mongoose.promise = require('bluebird'); let connection = mongoose.createconnection('mongodb://localhost:27017/forum'); mai.initialize(connection); 

fixed it, problem required mongoose in model file when should've done pass mongoose entry point.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -