intro-mongo-db
intro-mongo-db copied to clipboard
betaUser default
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)
I am also having the same issue. And I see a very strange error in the console. MongoError: pool is draining, new operations prohibited
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 your solution also made the test betaUser should default to false
pass for me, but should have correct fields
is still failing.
for me the code @chrisueda provided only fix the pool is draining issue, but betauser and correct fields still both are failing...
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.
@josephmwells your solution worked for me
thanks @josephmwells it works now