@@ -13,6 +13,7 @@ const EventEmitter = require('events').EventEmitter;
13
13
const Kareem = require ( 'kareem' ) ;
14
14
const MongooseBuffer = require ( './types/buffer' ) ;
15
15
const MongooseError = require ( './error/index' ) ;
16
+ const ObjectParameterError = require ( './error/objectParameter' ) ;
16
17
const OverwriteModelError = require ( './error/overwriteModel' ) ;
17
18
const Query = require ( './query' ) ;
18
19
const SaveOptions = require ( './options/saveOptions' ) ;
@@ -118,10 +119,15 @@ const saveToObjectOptions = Object.assign({}, internalToObjectOptions, {
118
119
119
120
function Model ( doc , fields , skipId ) {
120
121
if ( fields instanceof Schema ) {
121
- throw new TypeError ( '2nd argument to `Model` must be a POJO or string, ' +
122
+ throw new TypeError ( '2nd argument to `Model` constructor must be a POJO or string, ' +
122
123
'**not** a schema. Make sure you\'re calling `mongoose.model()`, not ' +
123
124
'`mongoose.Model()`.' ) ;
124
125
}
126
+ if ( typeof doc === 'string' ) {
127
+ throw new TypeError ( 'First argument to `Model` constructor must be an object, ' +
128
+ '**not** a string. Make sure you\'re calling `mongoose.model()`, not ' +
129
+ '`mongoose.Model()`.' ) ;
130
+ }
125
131
Document . call ( this , doc , fields , skipId ) ;
126
132
}
127
133
@@ -3099,6 +3105,9 @@ Model.$__insertMany = function(arr, options, callback) {
3099
3105
const toExecute = arr . map ( ( doc , index ) =>
3100
3106
callback => {
3101
3107
if ( ! ( doc instanceof _this ) ) {
3108
+ if ( doc != null && typeof doc !== 'object' ) {
3109
+ return callback ( new ObjectParameterError ( doc , 'arr.' + index , 'insertMany' ) ) ;
3110
+ }
3102
3111
try {
3103
3112
doc = new _this ( doc ) ;
3104
3113
} catch ( err ) {
0 commit comments