I could use some help filtering various values from the couchdb view. I have a database that stores logs with information about computers. Periodically, new logs for the computer are recorded in db.
In a slightly simplistic way, I store entries like these:
{
"name": "NAS",
"os": "Linux",
"timestamp": "2011-03-03T16:26:39Z",
}
{
"name": "Server1",
"os": "Windows",
"timestamp": "2011-02-03T19:31:31Z",
}
{
"name": "NAS",
"os": "Linux",
"timestamp": "2011-02-03T18:21:29Z",
}
So far I am trying to filter this list with separate entries. What I would like to get is the last log file for each device.
I have a view like this:
function(doc) {
emit([doc.timestamp,doc.name], doc);
}
Im requesting this view using python (couchdbkit) and the best solution I came up with is like this:
def get_latest_logs(cls):
unique_names = []
unique = []
for log in cls.view("logs/timestamp", descending=True):
if log.name not in unique_names:
unique_names.append(log.name)
unique.append(log)
return unique
... . , , python ( ).
, ,
, .
, , , - ( couchdb) , .
,
Andreas