Best practices for storing IPs and view retrieval
Looking for advice on storing system IPs.
Currently having some difficulty storing them and then retrieving counts of systems based on dates.
function (doc) {
if(doc.CACHEINSERTEPOCH && doc.PROXYIP) {
emit([doc.PROXYIP,doc.CACHEINSERTEPOCH],doc.PROXYIP,null);
}
}
reduce _count
Kind of works. Using startkey of '000.000.000.000' and endkey of '999.999.999.999' I got all the servers and the counts appear proper, except one server is missing. When I explicitly ask for that server i get those values.
Seems there should be a better safer way to get all IPs based on an epoch period counts.
Thanks in advance.
Tim
Hello
In addition to the comment made by Dipti I am inviting your to take a look to these blog posts that are quite helpful where working with queries (sorting, range, compound keys...)
- Sorting : http://blog.couchbase.com/understanding-letter-ordering-view-queries
- Compound Keys : http://blog.couchbase.com/understanding-grouplevel-view-queries-compound...
Regards
Thanks everyone. Very helpful.
I've changed the map to:
function (doc) {
if(doc.CACHEINSERTEPOCH && doc.PROXYIP) {
emit([doc.PROXYIP,doc.CACHEINSERTEPOCH],null);
}
}
and set group level to 1 to get the _count of the PROXYIP.
Works great; EXCEPT;
There is a server missing.
The 9 servers on the 4.31.xxx.xxx domain all show up with counts perfectly.
The 1 development server on 8.29.xxx.xxx does not show up at all. I have verified the documents for this server are there and accessible.
I tried it with now start/end key and with a start key of ["0",0] and end key of ["Z",9359981403] nothing seems to make a difference.
If I set the start/end keys to be explicitly the lost server, it does return fine. But then it's just the 1 server and the 9 are out of the key ranges.
Thanks again.
Hello,
Can you share the exact keys that we do some tests?
Regards
Tim,
Your emit statement should only include the key and the value. You can use a compound key. So in your example, you should emit
emit([doc.PROXYIP,doc.CACHEINSERTEPOCH],null);
This will return the document IDs when you execute a range lookup. Also, depending on what you are looking for you may need to use the inclusive_end parameter.