我使用 NodeJS 开发了一个移动 Web 应用程序。所有用户无需身份验证即可访问数据(食物、菜单等)。他们可以列出产品,喜欢它们,或者将它们标记为最喜欢的..等等我想要的是给他们唯一的ID(第一次访问时)以便在他们每次访问时识别它们,并通过将这些操作存储在我的数据库中来跟踪他们的操作想要这样,因为当他们重新访问我的应用程序时,我会说“您本月已将 3 款产品标记为最爱!” 或“显然你喜欢汉堡包(列出汉堡类别 22 次)
如果为真,则列出用户最近的活动,例如;
var uID = "ID data on client-side."
db.users.findOne({ userID: uID }, function(err, user){
if(err){
res.send("you are here for the first time!");
// >>> create new unique ID HERE and assign it to the user !!<<<
} else {
res.send("you were here before");
// already have an ID, go on
}
}) …Run Code Online (Sandbox Code Playgroud)