intro-mongo-db icon indicating copy to clipboard operation
intro-mongo-db copied to clipboard

betaUser default

Open vjandrei opened this issue 5 years ago • 7 comments

I have on the start user.js

betaUser: { type: Boolean, default: false },

like that but the test is not passing it? betaUser should default to false (11ms)

Here is the full schema

const mongoose = require('mongoose') const userSchema = new mongoose.Schema({ firstName: { type: String, required: true }, lastName: { type: String, required: true }, email: { type: String, required: true, unique: true }, betaUser: { type: Boolean, default: false }, birthDate: Date, address: { other: Boolean, street: String, houseNumber: Number, zip: Number, city: String, State: String }, pets: [{type: String}] }) module.exports = mongoose.model('user', userSchema)

vjandrei avatar Dec 10 '19 06:12 vjandrei

I am also having the same issue. And I see a very strange error in the console. MongoError: pool is draining, new operations prohibited

sandeep206 avatar Jan 19 '20 13:01 sandeep206

It seems like passing the options object like this:

  return mongoose.connect(url, {
    poolSize: 100,
    useNewUrlParser: true,
    useUnifiedTopology: true
  });
};

Solved the pool is draining issue for me.

chrisueda avatar Mar 24 '20 22:03 chrisueda

@chrisueda your solution also made the test betaUser should default to false pass for me, but should have correct fields is still failing.

mkelley33 avatar Apr 21 '20 03:04 mkelley33

for me the code @chrisueda provided only fix the pool is draining issue, but betauser and correct fields still both are failing...

thebestfella avatar Apr 29 '20 00:04 thebestfella

in testconfig.js, I had to move mongoose.disconnect() from afterEach to afterAll . I think mongodb just didn't like the rapid connecting and disconnecting ? I"m not sure if this is a fix, but it's definitely a hack that worked.

joeyfurness avatar Jul 26 '20 19:07 joeyfurness

@josephmwells your solution worked for me

AbdouTanta avatar Aug 29 '20 16:08 AbdouTanta

thanks @josephmwells it works now

Anksus avatar Oct 20 '20 19:10 Anksus