Error: '_ts' field only supports 'expireAfterSeconds' option

I am using Cosmos DB version 3.6 as a session store in Node.js. I have the following code:

const expressSession = require("express-session");
const MongoStore = require("connect-mongo")(expressSession);
const store = new MongoStore({
        mongooseConnection: mongoose.connection,
        ttl:24 * 60 * 60 * 1000,
})

This code results in the following error message:

  (node:16068) UnhandledPromiseRejectionWarning: MongoError: The 'expireAfterSeconds' option is supported on '_ts' field only.

What is the solution for this problem?

The solution to this problem is to remove the ttl property from the MongoStore constructor options and instead use the expires property in the express-session options. The updated code should look like this:

const expressSession = require("express-session");
const MongoStore = require("connect-mongo")(expressSession);
const store = new MongoStore({
        mongooseConnection: mongoose.connection,
})
app.use(expressSession({
        secret: "my-secret",
        resave: false,
        saveUninitialized: false,
        store: store,
        cookie: {
                maxAge: 24 * 60 * 60 * 1000
        },
        expires: new Date(Date.now() + (24 * 60 * 60 * 1000))
}))

This will set the session expiration time to 24 hours and use the _ts field in Cosmos DB to automatically expire sessions.