문제

I want to record user events to my mongodb collection. Is it possible to set up a simple query to only store the last recorded time stamp for an event for an arbitrary, dynamically changing set of events (so when a new event is received, it is inserted)?

I know the following doesn't work, but i wanted to give an idea of what I'm thinking:

uievents.update({_id:id},{
    $set: {userName:user,
                   ("events."+eventName): {
                eventName: eventName,
                serverTime: curTime,
                browserTime: btime,
                value: value
            }},{$upsert:true});
도움이 되었습니까?

해결책

Easiest way to do his is really simple:

query = {$set: {}}
query["$set"]["event."+eventName] = {
                eventName: eventName,
                serverTime: curTime,
                browserTime: btime,
                value: value
            }

uievents.update({_id:id},query,{$upsert:true});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top