TypeError: Cannot read property 'ownerDocument' of null
See original GitHub issueIntent Upsert a document
Problem I got a “TypeError: Cannot read property ‘ownerDocument’ of null” on function upsertError
Schema Attached (customer.js.txt) customer.js.txt
Code snippet
router.post('/cliente', passwordless.restricted(restrictedOptions), function (req, res) {
req.check('latitude', 'Não foi possível determinar a latitude do endereço especificado').isDecimal();
req.check('longitude', 'Não foi possível determinar a longitude do endereço especificado').isDecimal();
req.check('name', 'O nome especificado não é alfanumérico').notEmpty();
req.check('email', 'O e-mail especificado não é válido').isEmail();
req.check('address', 'O endereço especificado não é válido').notEmpty();
req.getValidationResult()
.then(function checkPostClienteValidationResult (result) {
if (result.isEmpty()) {
const customerData = {
name: req.sanitize('name').trim(),
email: req.sanitize('email').normalizeEmail(),
phone: req.sanitize('phone').trim(),
address: {
coordinates: {
type: 'Point',
coordinates: [req.sanitize('longitude').toFloat(), req.sanitize('latitude').toFloat()]
},
streetAddress: req.sanitize('address').trim(),
public: ((typeof req.body.address_is_public === 'undefined') ? false : true)
},
legalId: req.sanitize('legal_id').trim(),
notes: req.sanitize('notes').trim()
};
const isUpdate = (typeof req.body.id === 'string') && (req.body.id !== '');
debug('Upserting customer (update: %s), customer data: %j', isUpdate, customerData);
const updateQuery = {
_id: (isUpdate ? req.body.id : mongoose.Types.ObjectId())
};
const updateOptions = {
upsert: true,
runValidators: true,
setDefaultsOnInsert: true
};
Customer.findOneAndUpdate(updateQuery, customerData, updateOptions)
.exec()
.then(function upsertDone (customer) {
debug('Upsert finished, customer data: %j', customer);
var flashMessage;
if (isUpdate) {
flashMessage = 'O cliente foi atualizado com sucesso';
} else {
flashMessage = 'O cliente foi adicionado com sucesso';
}
req.flash(flashMessage);
res.redirect(dashboardCustomersPath);
}, function upsertError (err) {
debug('Customer upsert error: %s', err);
for (const key in err.errors) {
if (err.errors.hasOwnProperty(key)) {
req.flash('danger', err.errors[key].message);
}
}
res.redirect(dashboardCustomersPath);
});
} else {
res.redirect(dashboardCustomersPath);
}
});
});
Notes Mongoose version: 4.7.5 Nodejs version: 7.3.0
Issue Analytics
- State:
- Created 7 years ago
- Comments:5
Top Results From Across the Web
Uncaught TypeError: Cannot read property 'ownerDocument ...
I think my view is returning proper JSON but now data is not being added to the .mainContent div. It gives this error:...
Read more >Can not read property ownerDocument of null #542 - GitHub
I am getting TypeError: Cannot read property 'ownerDocument' of null even if all the required props are passed to Container and element.
Read more >Cannot read property 'ownerDocument' of undefined - Laracasts
I put a child component called <page-buttons> in my main Vue component. This component has some buttons floating on the page.
Read more >cannot read properties of null (reading 'ownerdocument')
I am getting TypeError: Cannot read property 'ownerDocument' of null even if all the required props are passed to Container and element. Line...
Read more >Cannot read property ownerDocument of null - Mendix Forum
The page doesn't receive an object. Perhaps because of access rights or because there is no object passed to the page.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Add the
context
option to your query:As specified in the mongoose-unique-validator docs
No idea, we don’t have formally supported typescript bindings, so report an issue to whoever maintains yours.