@@ -13,6 +13,7 @@ const EventEmitter = require('events').EventEmitter;
1313const Kareem = require ( 'kareem' ) ;
1414const MongooseBuffer = require ( './types/buffer' ) ;
1515const MongooseError = require ( './error/index' ) ;
16+ const ObjectParameterError = require ( './error/objectParameter' ) ;
1617const OverwriteModelError = require ( './error/overwriteModel' ) ;
1718const Query = require ( './query' ) ;
1819const SaveOptions = require ( './options/saveOptions' ) ;
@@ -118,10 +119,15 @@ const saveToObjectOptions = Object.assign({}, internalToObjectOptions, {
118119
119120function Model ( doc , fields , skipId ) {
120121 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, ' +
122123 '**not** a schema. Make sure you\'re calling `mongoose.model()`, not ' +
123124 '`mongoose.Model()`.' ) ;
124125 }
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+ }
125131 Document . call ( this , doc , fields , skipId ) ;
126132}
127133
@@ -3099,6 +3105,9 @@ Model.$__insertMany = function(arr, options, callback) {
30993105 const toExecute = arr . map ( ( doc , index ) =>
31003106 callback => {
31013107 if ( ! ( doc instanceof _this ) ) {
3108+ if ( doc != null && typeof doc !== 'object' ) {
3109+ return callback ( new ObjectParameterError ( doc , 'arr.' + index , 'insertMany' ) ) ;
3110+ }
31023111 try {
31033112 doc = new _this ( doc ) ;
31043113 } catch ( err ) {
0 commit comments