小编Ion*_*Kat的帖子

Mongoose 和 connect-mongo

我正在使用 mongoose 来管理数据之间的关系,并且尝试使用 connect-mongo 在数据库中存储特定会话。

看起来我们需要两次连接到数据库,一次使用 mongoose,另一次使用 connect-mongo。

我使用以下代码来初始化猫鼬的连接

await mongoose.connect(this._connectionUrl, this._connectionOptions);
Run Code Online (Sandbox Code Playgroud)

每次初始化一个新商店(不确定我关于代码初始化是否正确)。

app.use(session({
            // secret: config.sessionSecretKey,
            secret: "secretkey",
            resave: true,
            saveUninitialized: true,
            cookie: { maxAge: 19 * 60000 }, // store for 19 minutes
            store: MongoStore.create({
                mongoUrl: this._connectionUrl,
                mongoOptions: this._connectionOptions // See below for details
            })
        }))
Run Code Online (Sandbox Code Playgroud)

有什么方法可以将连接从 mongoose 传递到 mongo-connect Store 吗?

session mongoose mongodb session-cookies node.js

4
推荐指数
1
解决办法
4332
查看次数

isInterrupted() 没有被触发

尝试使用interrupt(),发现isInterrupted() 始终为false。

另一件事是用Thread.interrupted()替换isInterrupted()将使线程停止。

有人可以解释为什么会发生这种行为吗?

public static void main(String[] args) {
        Thread counter = new Thread(new Worker());
        counter.start();
        counter.interrupt();
    }

    static class Worker extends Thread {

        @Override
        public void run() {
            String msg = "It was interrupted"; 

            while (true) {
                if (isInterrupted()) {
                    System.out.println(msg);
                    return;
                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

java multithreading java-8

3
推荐指数
1
解决办法
58
查看次数