打算在Heroku / Node / Express / Mongodb网络应用程序中记录API的使用(用户/路径/参数/时间),以允许各种分析(谁/什么/何时/多久)。我能想到的一种方法是将它们推送到MongoDB。
Mongo会自动生成一个ID,我发现extract the created time from the autogenerated ID可以,但由于时间戳是我想要的,现在我想知道我是否可以使用日期作为身份证?
这似乎有效,时间戳似乎足够精细("_id" : ISODate("2012-11-30T21:18:24.484Z")
),它们将是唯一的。这是可以的,或只是在事情发生时只是要求“ID not unique”错误?
var apilogSchema = new mongoose.Schema({
_id: {type: Date, default: Date.now},
userId: {type: mongoose.Schema.Types.ObjectId, required: false},
route: {type: String, required: false}
})
答案 0 :(得分:1)
如果你在node.js上,请查看node-uuid并希望你的id包含时间戳