code: function validateDocMongoose(mongoose, collectionname, schema, doc) {
      var DocModel;
      //console.log('schema ' + JSON.stringify(schema));
      if (mongoose.modelNames().indexOf(collectionname) >= 0) {
          DocModel = mongoose.model(collectionname);
      }
      else {
          DocModel = mongoose.model(collectionname, schema);
      }
      return validateDocVsMongooseModel(DocModel, doc);
  }
docs: /*
  export function getModelRecByModelName(mongoose : any, modelPath: string, modelName : string) : Promise<IModelRec>  {
  do we have the meta collection in the db?
  return Promise.all([
  mongoose.connection.db[MongoNLQ.COLL_METAMODELS].find({ modelName : modelName}),
  mongoose.connection.db[MongoNLQ.COLL_EXTENDEDSCHEMAS].find({ modelName : modelName})
  ]).then(res => {
  var modelDoc = res[0];
  var extendedSchema = res[1];
  var schema = makeMongooseSchema(extendedSchema);
  var model = mongoose.model(modelDoc.collectionName, schema);
  return {
  collectionName : modelDoc.collectionName,
  modelDoc : modelDoc,
  schema : makeMongooseSchema(extendedSchema),
  model : model
  } as IModelRec;
  });
  }
   /*
  hasMetaCollection(mongoose).then( () => {
  mongoose.connection.db.mgnlq_domains.find( {
  modelName : modelName
  }).then( doc => {
  if (doc.schema)
  });
  });
  mongoose.connection.db.listCollections().toArray((err ,names ) =>
  {
  if(names.indexOf("mgnlq_domains") >= 0) {
  
  }
  });
  }