These are chat archives for Automattic/mongoose

May 2016
Vlado Tesanovic
May 02 2016 13:50
Is there are official or unofficial mongo gitter chat? Anyone knows
Christoph Werner
May 02 2016 14:50

I'm writing a plugin that needs to retrieve a connection object in its options.

In tests, i do not only want to check if the connection property is set on options, but i would also love to perform an instanceof check to check if it's really a valid mongoose connection instance. Unfortunately, this doesn't work:

import { isPlainObject } from 'lodash'
import { Connection } from 'mongoose'

export default function (schema, options) {
  if (!isPlainObject(options)) {
    throw new Error('options must be an object')
  if (!(options.connection instanceof Connection)) {
    throw new Error('connection option must be a valid mongoose connection')

Am i missing something? Is there any other way to validate a connection?