抛出新的错误('必需的MongoStore选项`db` missing');

时间:2015-01-26 16:59:42

标签: node.js mongodb

启动本地节点服务器时,我得到以下内容。

致电DB

mongoose.connect('mongodb://localhost/mays');
app.locals.db = mongoose.connection;

错误消息

C:\var\www\stage.mayfieldafc.com\node_modules\connect-mongo\lib\connect-mongo.js:157
    throw new Error('Required MongoStore option `db` missing');
          ^
Error: Required MongoStore option `db` missing

Mongoos.connection的输出

{ base:
   { connections: [ [Circular] ],
     plugins: [],
     models: { User: [Object] },
     modelSchemas: { User: [Object] },
     options: { pluralization: true } },
  collections:
   { users:
      { collection: null,
        opts: [Object],
        name: 'users',
        conn: [Circular],
        queue: [],
        buffer: true } },
  models:
   { User:
      { [Function: model]
        base: [Object],
        modelName: 'User',
        model: [Function: model],
        db: [Circular],
        discriminators: undefined,
        schema: [Object],
        options: undefined,
        collection: [Object] } },
  replica: false,
  hosts: null,
  host: 'localhost',
  port: 27017,
  user: undefined,
  pass: undefined,
  name: 'mays',
  options:
   { db: { read_preference: 'primary', forceServerObjectId: false, w: 1 },
     auth: {},
     server: { socketOptions: [Object], auto_reconnect: true },
     replset: { socketOptions: {} } },
  otherDbs: [],
  _readyState: 2,
  _closeCalled: false,
  _hasOpened: false,
  _listening: false,
  _events: {},
  db:
   { domain: null,
     _events: {},
     _maxListeners: 10,
     databaseName: 'mays',
     serverConfig:
      { domain: null,
        _events: {},
        _maxListeners: 10,
        _callBackStore: [Object],
        _commandsStore: [Object],
        auth: [Object],
        _dbStore: [Object],
        host: 'localhost',
        port: 27017,
        options: [Object],
        internalMaster: false,
        connected: false,
        poolSize: 5,
        disableDriverBSONSizeCheck: false,
        _used: true,
        replicasetInstance: null,
        emitOpen: true,
        ssl: false,
        sslValidate: false,
        sslCA: null,
        sslCert: undefined,
        sslKey: undefined,
        sslPass: undefined,
        serverCapabilities: null,
        name: 'localhost:27017',
        socketOptions: [Object],
        logger: [Object],
        eventHandlers: [Object],
        _serverState: 'connecting',
        _state: [Object],
        recordQueryStats: false,
        socketTimeoutMS: [Getter/Setter],
        db: [Circular],
        dbInstances: [Object],
        connectionPool: [Object] },
     options: { read_preference: 'primary', forceServerObjectId: false, w: 1 },
     _applicationClosed: false,
     slaveOk: false,
     bufferMaxEntries: -1,
     native_parser: undefined,
     bsonLib:
      { Code: [Object],
        Symbol: [Object],
        BSON: [Object],
        DBRef: [Object],
        Binary: [Object],
        ObjectID: [Object],
        Long: [Object],
        Timestamp: [Object],
        Double: [Object],
        MinKey: [Object],
        MaxKey: [Object],
        promoteLongs: true },
     bson: { promoteLongs: true },
     bson_deserializer:
      { Code: [Object],
        Symbol: [Object],
        BSON: [Object],
        DBRef: [Object],
        Binary: [Object],
        ObjectID: [Object],
        Long: [Object],
        Timestamp: [Object],
        Double: [Object],
        MinKey: [Object],
        MaxKey: [Object],
        promoteLongs: true },
     bson_serializer:
      { Code: [Object],
        Symbol: [Object],
        BSON: [Object],
        DBRef: [Object],
        Binary: [Object],
        ObjectID: [Object],
        Long: [Object],
        Timestamp: [Object],
        Double: [Object],
        MinKey: [Object],
        MaxKey: [Object],
        promoteLongs: true },
     _state: 'connecting',
     pkFactory:
      { [Function: ObjectID]
        index: 12355790,
        createPk: [Function: createPk],
        createFromTime: [Function: createFromTime],
        createFromHexString: [Function: createFromHexString],
        isValid: [Function: isValid],
        ObjectID: [Circular],
        ObjectId: [Circular] },
     forceServerObjectId: false,
     safe: false,
     notReplied: {},
     isInitializing: true,
     openCalled: true,
     commands: [],
     logger: { error: [Function], log: [Function], debug: [Function] },
     tag: 1422291172449,
     eventHandlers:
      { error: [],
        parseError: [],
        poolReady: [],
        message: [],
        close: [] },
     serializeFunctions: false,
     raw: false,
     recordQueryStats: false,
     retryMiliSeconds: 1000,
     numberOfRetries: 60,
     readPreference: undefined } }

此代码正在另一台计算机上运行。当我提供一个有效的数据库名称,我可以通过Robomongo

连接时,我有点难以理解为什么会出现此错误

3 个答案:

答案 0 :(得分:3)

更改您从

传递给connect-mongo 的选项
var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
app.use(session({
    db: new MongoStore({ db: mongoose.connection.db })
}));

var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
app.use(session({
   db: new MongoStore({ mongooseConnection: mongoose.connection })
}));

这里记载了所有内容:https://github.com/kcbanner/connect-mongo,真的。

答案 1 :(得分:1)

另外,请确保您是最新的。在旧版本中,“mongooseConnection”#39;选项是' mongoose_connection'。 Misnaming会触发db missing错误。

答案 2 :(得分:1)

令人惊讶的是......或者声音,我没有创造

Set-TridionCoreServiceSettings sdswpap004 2013-SP1
$client = Get-TridionCoreServiceClient

Write-Output "Getting the title"
$pageTitle = Get-TridionItem -Id "tcm:30-7386-64" | Select-Object Title
Write-Output $pageTitle

$publishInfo = $client.GetListPublishInfo("tcm:30-7386-64")



if ($publishInfo) {
    Write-Output "Getting the last pablished date: "
    Write-Output $publishInfo.PublishedAt | Out-String
}

作为数据库,所以它试图连接到任何东西......

确保您已创建数据库:)