gpt4 book ai didi

node.js - 抛出新的错误 ('Required MongoStore option ` db`missing');

转载 作者:IT老高 更新时间:2023-10-28 13:27:37 24 4
gpt4 key购买 nike

当我启动本地 Node 服务器时,我得到以下信息。

调用数据库

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

连接的有效数据库名称时,我有点困惑为什么我可能会收到此错误

最佳答案

将您传递的选项更改为 connect-mongo from

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 ,真的。

关于node.js - 抛出新的错误 ('Required MongoStore option ` db`missing');,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28154942/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com