为什么在mongoose对象中看不到mongoose.connect?

时间:2019-08-23 22:00:39

标签: node.js mongoose

问题:当我console.log(mongoose)检查其内容时,没有看到mongoose.connect。为什么会这样呢?我不了解什么基本的力学原理?

背景:安装并需要猫鼬后,我记录了猫鼬对象以查看其中的内容。令我惊讶的是,我没有看到mongoose.connect。我使用这种方法登录到我的测试数据库中,

mongoose.connect(process.env.DB_CONNECTION, { useNewUrlParser: true })
    .then()
    .catch();

此方法起作用,因此我认为当查看猫鼬对象时mongoose.connect将可见。但这不是。

Mongoose {
  connections:
   [ NativeConnection {
       base: [Circular],
       collections: [Object],
       models: [Object],
       config: [Object],
       replica: false,
       options: null,
       otherDbs: [],
       relatedDbs: {},
       states: [Object],
       _readyState: 1,
       _closeCalled: false,
       _hasOpened: true,
       plugins: [],
       _listening: false,
       _connectionOptions: [Object],
       client: [MongoClient],
       '$initialConnection': [Promise],
       name: 'test',
       host: 'testcluster',
       port: 27017,
       user: 'testUser',
       pass: 'test',
       db: [Db] } ],
  models: { article: Model { article } },
  modelSchemas:
   { article:
      Schema {
        obj: [Object],
        paths: [Object],
        aliases: {},
        subpaths: {},
        virtuals: [Object],
        singleNestedPaths: {},
        nested: {},
        inherits: {},
        callQueue: [],
        _indexes: [],
        methods: {},
        methodOptions: {},
        statics: {},
        tree: [Object],
        query: {},
        childSchemas: [],
        plugins: [Array],
        '$id': 1,
        s: [Object],
        _userProvidedOptions: {},
        options: [Object],
        '$globalPluginsApplied': true } },
  options: { pluralization: true },
  _pluralize: [Function: pluralize],
  Schema:
   { [Function: Schema]
     reserved:
      [Object: null prototype] {
        _posts: 1,
        _pres: 1,
        populated: 1,
        remove: 1,
        validate: 1,
        toObject: 1,
        schema: 1,
        save: 1,
        modelName: 1,
        get: 1,
        isNew: 1,
        isModified: 1,
        init: 1,
        errors: 1,
        db: 1,
        collection: 1,
        removeListener: 1,
        listeners: 1,
        once: 1,
        on: 1,
        emit: 1,
        prototype: 1 },
     Types:
      { String: [Function],
        Number: [Function],
        Boolean: [Function],
        DocumentArray: [Function],
        Embedded: [Function: SingleNestedPath],
        Array: [Function],
        Buffer: [Function],
        Date: [Function],
        ObjectId: [Function],
        Mixed: [Function],
        Decimal: [Function],
        Decimal128: [Function],
        Map: [Function: Map],
        Oid: [Function],
        Object: [Function],
        Bool: [Function],
        ObjectID: [Function] },
     ObjectId:
      { [Function: ObjectId]
        schemaName: 'ObjectId',
        get: [Function],
        _checkRequired: [Function],
        _cast: [Function: castObjectId],
        cast: [Function: cast],
        checkRequired: [Function] } },
  model: [Function],
  plugins:
   [ [ [Function], [Object] ],
     [ [Function], [Object] ],
     [ [Function], [Object] ],
     [ [Function], [Object] ] ] }

0 个答案:

没有答案