我在monogdb上有一个巨大的日志事件集合,每个事件都有一个唯一的id。
一个非常简单的例子:
我想找到一个特定的事件(比如第3个product create
事件),我想在之前获取 10个事件,之后 10个事件。
用mongodb甚至可以吗?
我正在使用Mongoose和NodeJs
谢谢!
答案 0 :(得分:0)
如果您对事件有唯一的DirectoryIndex index.html
,这将有效:
timestamp
<强>更新强> 如果你没有为每个事件设置时间戳(这确实是错误的),这应该有效:
Model.find({"event": "user created a product"}).skip(2).exec(function (err, docs)
{
var myEvent = docs[0];
Model.find({timestamp: {$gt: myEvent.timestamp}}).limit(10).exec(function (error, records)
{
console.log(records);
});
});