Forum

How to find mode value in db8?

How can I find the most frequent value from the boolean type value and number type value in db8?

I'm asking a question because I can't think of a solution even after reading this document.

@ideasidus
Can you elaborate your query ?

How do I create a query to find the most common value in a DB8 field with {type:number}?

I understand that SQL can print the most frequent value through Group by and count, and similarly in Mongo DB, is it possible in DB8 as well?

Aggregate functions are supported by db8.
Refer the below schema file for supported aggregate functions. db8/MojDbServiceSchemas.cpp at master · webosose/db8 · GitHub

Example:
The below command will group by same music titles and returns count in each group.

luna-send -n 1 -f -m com.palm.configurator luna://com.webos.service.db/find '{ "query" : { "aggregate": {"groupBy": ["musicTitle"], "cnt":["musicTitle"]}, "from":"com.webos.music:1" } }'

output:

{
    "returnValue": true,
    "results": [
        {
            "groupBy": {
                "musicTitle": "Dil se re"
            },
            "musicTitle": {
                "cnt": 2
            }
        },
        {
            "groupBy": {
                "musicTitle": "Luka Chuppi"
            },
            "musicTitle": {
                "cnt": 3
            }
        },
        {
            "groupBy": {
                "musicTitle": "SONG song"
            },
            "musicTitle": {
                "cnt": 1
            }
        },
        {
            "groupBy": {
                "musicTitle": "abcd"
            },
            "musicTitle": {
                "cnt": 1
            }
        }
    ]
}