Couchbase Query not working as expected


#1

using Couchbase 4.1 I have the following document structure

"bucketName": {
                "UserId": "user1",
                "skillSet": {
                    "punchPower": 1,
                    "kickPower": 1,
                    "specialPower": "Extreme programmer"
                },
                "id": "GameUser_XXX1D",
                "timestamp": 1464935606358
            }

I want a query which will return me back the most recent timestamp and the total number of all matches this is what I have.

select count(timestamp) as users, timestamp from bucketName where id like 'GameUser__%' AND 
skillSet.specialPower = 'Extreme Programmer' AND 
skillSet.kickPower = 1 AND 
skillSet.punchPower = 1 AND 
timestamp BETWEEN $sometimeIPassHere AND $sometimeIPassHere 
ORDER BY timestamp desc limit 1;
This returns back the correct number of users as I expect but the timestamp that is being returned is incorrect the oldest timestamp is being returned as if the desc is not being considered in my query. I've tried removing, and applying ascwhich also returned the same result.

My question is this How can I resolve this incorrect query result what am I doing wrong?


#2

How about this one;

select count(timestamp) as users, max([timestamp, b1])
from bucketName b1 where id like ‘GameUser__%’ AND
skillSet.specialPower = ‘Extreme Programmer’ AND
skillSet.kickPower = 1 AND
skillSet.punchPower = 1 AND
timestamp BETWEEN $sometimeIPassHere AND $sometimeIPassHere;


#3

Thank modifying this a hair worked for me. I had to get rid of the b1 references with it the entire document was being returned instead of just the field i wanted thanks again!