简体   繁体   English

猫鼬连接中只有一种模型

[英]Only one model in mongoose connection

I logged my connection and got this:我记录了我的连接并得到了这个:

// Connect to Mongo
const promise = mongoose 
  .connect(db, { 
    useNewUrlParser: true,
    useCreateIndex: true, 
    useUnifiedTopology: true, 
    useFindAndModify: false }) // Adding new mongo url parser 
  .then(() => console.log('MongoDB Connected...')) 
  .catch(err => console.log(err)); 

  console.log(promise);

Here' what is logged:这是记录的内容:

Promise { <pending> }
NativeConnection {
  base: Mongoose {
    connections: [ [Circular] ],
    models: { user: Model { user } },
    modelSchemas: { user: [Schema] },
    options: { pluralization: true, [Symbol(mongoose:default)]: true },
    _pluralize: [Function: pluralize],
    Schema: [Function: Schema] {
      reserved: [Object: null prototype],
      Types: [Object],
      ObjectId: [Function]
    },
    model: [Function],
    plugins: [ [Array], [Array], [Array], [Array], [Array] ]
  },
  collections: {
    users: NativeCollection {
      collection: null,
      Promise: [Function: Promise],
      _closed: false,
      opts: [Object],
      name: 'users',
      collectionName: 'users',
      conn: [Circular],
      queue: [],
      buffer: true,
      emitter: [EventEmitter]
    }
  },
  models: { user: Model { user } },
  config: { autoIndex: true, useCreateIndex: true, useFindAndModify: false },
  replica: false,
  options: null,
  otherDbs: [],
  relatedDbs: {},
  states: [Object: null prototype] {
    '0': 'disconnected',
    '1': 'connected',
    '2': 'connecting',
    '3': 'disconnecting',
    '99': 'uninitialized',
    disconnected: 0,
    connected: 1,
    connecting: 2,
    disconnecting: 3,
    uninitialized: 99
  },
  _readyState: 2,
  _closeCalled: false,
  _hasOpened: false,
  plugins: [],
  id: 0,
  _listening: false,
  _connectionString: 'Sorry, but cannot pass :)',
  _connectionOptions: {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    promiseLibrary: [Function: Promise],
    driverInfo: { name: 'Mongoose', version: '5.10.3' }
  },
  client: MongoClient {
    _events: [Object: null prototype] {},
    _eventsCount: 0,
    _maxListeners: undefined,
    s: {
      url: 'sorry, but cannot pass :)', 
      options: [Object],
      promiseLibrary: [Function: Promise],
      dbCache: Map {},
      sessions: Set {},
      writeConcern: undefined,
      namespace: [MongoDBNamespace]
    },
    [Symbol(kCapture)]: false
  },
  '$initialConnection': Promise { <pending> },
  then: [Function],
  catch: [Function],
  _events: [Object: null prototype] {
    open: [Function: bound onceWrapper] { listener: [Function] }
  },
  _eventsCount: 1

The problem is that I have three models: post, user and message and because of that I cannot for example upload file with multer for message or post.问题是我有三个模型:post、user 和 message,因此我无法上传带有 multer 的文件以进行消息或发布。 Why is it happening?为什么会发生? It cannot be a problem with my cluster, because I have second database on that cluster in other projects that works( which have implemented the same things, but with correct effect).我的集群不会有问题,因为我在其他有效的项目中在该集群上有第二个数据库(已经实现了相同的东西,但效果正确)。

The only issue I think can be happening with this connection you might be passing a new schema and model that you will see in your object is with that schema.我认为此连接可能会发生的唯一问题您可能会传递一个新的架构和模型,您将在对象中看到该架构。 You don't get all schemas from the cloud, the schema being returned is the one that exists with this connection.您不会从云中获取所有架构,返回的架构是此连接中存在的架构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM