I have a very minimal model:
var CompanySchema = new mongoose.Schema({
name: { type: String, required: true, unique: true },
});
var Company = mongoose.model('Company', CompanySchema)
I am attempting to add a single document if it doesn't exist. Currently, there are no documents while I test:
models.Company.findOneAndUpdate({
name: 'companyName'
}, {upsert: true}, function(err, numberAffected, raw){
console.log(err, numberAffected, raw)
})
This is using the upsert
options from the Mongoose docs
However err
is null
, numberAffected
is null. Why isn't my document updated?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…