Pre Exam Test Practice (SSC | Banking | IAS | GATE | State Level | CLAT | Railways | Insurance | Teaching Exams | NDA | Defence | IES |State Exam )

Organizational Research By

Surprising Reserch Topic

cannot overwrite model once compiled mongoose

cannot overwrite model once compiled mongoose  using -'node.js,mongodb,model,express,mongoose'

Not Sure what I'm doing wrong, here is my check.js

var db = mongoose.createConnection('localhost', 'event-db');
db.on('error', console.error.bind(console, 'connection error:'));
var a1= db.once('open',function(){
var user = mongoose.model('users',
user.find({},{},function (err, users) {
console.log("Username supplied"+username);
//doSomethingHere })});

and here is my insert.js

var mongoose = require('mongoose');
var user = mongoose.model('users',
{name:String,email:String,password: String,phone:Number,_enabled:Boolean});
var new_user = new user({,email:,
password: req.body.password,phone:, _enabled:false });{
if(err) console.log(err); });}

Whenever I'm trying to run check.js, I'm getting this error

Cannot overwrite 'users' model once compiled.

I understand that this error comes due to mismatching of Schema, but I cannot see where this is happening ? I'm pretty new to mongoose and nodeJS.

Here is what I'm getting from the client interface of my MongoDB:

MongoDB shell version: 2.4.6 connecting to: test
> use event-db
  switched to db event-db
> db.users.find()
  { "_id" : ObjectId("52457d8718f83293205aaa95"),
    "name" : "MyName",
    "email" : "",
    "password" : "myPassword",
    "phone" : 900001123,
    "_enable" : true


asked Sep 29, 2015 by mannumits1
0 votes

Related Hot Questions

Government Jobs Opening