Skip to content

Commit

Permalink
fix(document): fix(document): report castError when setting single ne…
Browse files Browse the repository at this point in the history
…sted doc to array

Fix #6753
Re: #6710
  • Loading branch information
vkarpov15 committed Jul 23, 2018
1 parent ce3e00b commit ebec9d4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/schema/embedded.js
Expand Up @@ -138,7 +138,7 @@ Embedded.prototype.cast = function(val, doc, init, priorVal) {
return val;
}

if (val != null && typeof val !== 'object') {
if (val != null && (typeof val !== 'object' || Array.isArray(val))) {
throw new ObjectExpectedError(this.path, val);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/utils.js
Expand Up @@ -8,6 +8,7 @@ const Decimal = require('./types/decimal128');
const ObjectId = require('./types/objectid');
const PromiseProvider = require('./promise_provider');
const cloneRegExp = require('regexp-clone');
const get = require('lodash.get');
const sliced = require('sliced');
const mpath = require('mpath');
const ms = require('ms');
Expand Down Expand Up @@ -417,7 +418,7 @@ exports.isObject = function(arg) {
*/

exports.isPOJO = function(arg) {
return arg != null && typeof arg === 'object';
return get(arg, 'constructor.name') === 'Object';
};

/*!
Expand Down

0 comments on commit ebec9d4

Please sign in to comment.