{"action":"created","issue":{"url":"https://api.github.com/repos/expressjs/session/issues/186","labels_url":"https://api.github.com/repos/expressjs/session/issues/186/labels{/name}","comments_url":"https://api.github.com/repos/expressjs/session/issues/186/comments","events_url":"https://api.github.com/repos/expressjs/session/issues/186/events","html_url":"https://github.com/expressjs/session/issues/186","id":96794217,"number":186,"title":"creating multiple session object with express-session","user":{"login":"pravin-mindstix","id":8807541,"avatar_url":"https://avatars.githubusercontent.com/u/8807541?v=3","gravatar_id":"","url":"https://api.github.com/users/pravin-mindstix","html_url":"https://github.com/pravin-mindstix","followers_url":"https://api.github.com/users/pravin-mindstix/followers","following_url":"https://api.github.com/users/pravin-mindstix/following{/other_user}","gists_url":"https://api.github.com/users/pravin-mindstix/gists{/gist_id}","starred_url":"https://api.github.com/users/pravin-mindstix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pravin-mindstix/subscriptions","organizations_url":"https://api.github.com/users/pravin-mindstix/orgs","repos_url":"https://api.github.com/users/pravin-mindstix/repos","events_url":"https://api.github.com/users/pravin-mindstix/events{/privacy}","received_events_url":"https://api.github.com/users/pravin-mindstix/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-07-23T11:44:14Z","updated_at":"2015-07-24T08:04:52Z","closed_at":null,"body":"Hi, i am using connect-mongo and express-session for session handling in my app.\r\n\r\nhere is my code : \r\napp.use(session({\r\ncookie: { maxAge: 1000 * 60 * 60 * 24, path : '/userprofile/user_Profile'} ,\r\n\r\n  secret: \"XXXX\" ,\r\n  store:new MongoStore({\r\n          db: config.db.name,\r\n          mongooseConnection:mongoose.connection, \r\n          collection: 'session', \r\n          stringify:false,\r\n          autoReconnect:true,\r\n          touchAfter: 24 * 3600 // time period in seconds\r\n  }),\r\n  saveUninitialized: true,\r\n  resave: true\r\n},function(err){\r\nconsole.log(err || 'connect-mongodb setup ok');\r\n}));\r\n\r\nproblem is that when app hit endpoint --> ( path : '/userprofile/user_Profile' ) then its creates session object every time. i don't want to create session every time.\r\n\r\nin this endpoint what i did is, first I validated session object in this session collection and if object is not present then i want to create new session for user.\r\n\r\nrequest.session.name=\"userId\"\r\n\r\n{ \"_id\" : \"wunv7rlnMcU3fz8ocfZWZKL0IBU09TLs\", \"session\" : { \"cookie\" : { \"originalMaxAge\" : 86399999, \"expires\" : ISODate(\"2015-07-24T09:55:12.052Z\"), \"secure\" : null, \"httpOnly\" : true, \"domain\" : null, \"path\" : \"/userprofile/user_Profile\" }, \"name\" : \"XX385XXX\", }, \"expires\" : ISODate(\"2015-07-24T09:55:12.052Z\"), \"lastModified\" : ISODate(\"2015-07-23T09:55:12.054Z\") }\r\n\r\nthis is my valid object.\r\n\r\nhere is empty session object is created on every call\r\n\r\n{ \"_id\" : \"E5uyuBN0mwVfkbMcgSKmKwT3FLNICl1W\", \"session\" : { \"cookie\" : { \"originalMaxAge\" : 86400000, \"expires\" : ISODate(\"2015-07-24T09:55:21.392Z\"), \"secure\" : null, \"httpOnly\" : true, \"domain\" : null, \"path\" : \"/userprofile/user_Profile\" } }, \"expires\" : ISODate(\"2015-07-24T09:55:21.392Z\"), \"lastModified\" : ISODate(\"2015-07-23T09:55:21.393Z\") }\r\n\r\n{ \"id\" : \"vcwnba_yGUf-CuE-wj8AWTrUIfx6Rmz\", \"session\" : { \"cookie\" : { \"originalMaxAge\" : 86400000, \"expires\" : ISODate(\"2015-07-24T10:10:30.636Z\"), \"secure\" : null, \"httpOnly\" : true, \"domain\" : null, \"path\" : \"/userprofile/user_Profiler\" } }, \"expires\" : ISODate(\"2015-07-24T10:10:30.636Z\"), \"lastModified\" : ISODate(\"2015-07-23T10:10:30.637Z\") }\r\n\r\nI don't understand what's wrong with this ? \r\nThanks for any help."},"comment":{"url":"https://api.github.com/repos/expressjs/session/issues/comments/124415438","html_url":"https://github.com/expressjs/session/issues/186#issuecomment-124415438","issue_url":"https://api.github.com/repos/expressjs/session/issues/186","id":124415438,"user":{"login":"pravin-mindstix","id":8807541,"avatar_url":"https://avatars.githubusercontent.com/u/8807541?v=3","gravatar_id":"","url":"https://api.github.com/users/pravin-mindstix","html_url":"https://github.com/pravin-mindstix","followers_url":"https://api.github.com/users/pravin-mindstix/followers","following_url":"https://api.github.com/users/pravin-mindstix/following{/other_user}","gists_url":"https://api.github.com/users/pravin-mindstix/gists{/gist_id}","starred_url":"https://api.github.com/users/pravin-mindstix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pravin-mindstix/subscriptions","organizations_url":"https://api.github.com/users/pravin-mindstix/orgs","repos_url":"https://api.github.com/users/pravin-mindstix/repos","events_url":"https://api.github.com/users/pravin-mindstix/events{/privacy}","received_events_url":"https://api.github.com/users/pravin-mindstix/received_events","type":"User","site_admin":false},"created_at":"2015-07-24T08:04:52Z","updated_at":"2015-07-24T08:04:52Z","body":"Hey Thanks gabeio,\r\n\r\nsaveUninitialized:false,\r\nresave: false,  \r\nworks for me, its not creating multiple session object, now need to test it on production as well where my two server is running with mongodb replication. Hope it will works there also.\r\n\r\nAwesome :100: "}}