Couchbase lite query equivalent to N1QL

.net

#1

I have documents of following struct:
“Name”: Doc1,
“Tag”: [
{
“Text”: “a”
},
]

“Name”: Doc2,
“Tag”: [
{
“Text”: “b”
},
]

“Name”: Doc3,
“Tag”: [
{
“Text”: “c”
},
]

“Name”: Doc4,
“Tag”: [
{
“Text”: “a”
},
{
“Text”: “b”
}
],

to get now a distinct for the tags and the number of elements i use

"SELECT DISTINCT s.Text as Tag, " +
"COUNT(s) as Count " +
"FROM " + context.Name.AddGraveAccent() + " " +
“d UNNEST d.Tag AS s WHERE d.Type =’” + typeof(tt).Name + "’ " +
“AND s.Text IS NOT NULL Group by s”;

and i will get a result for each tag and their count:

a, 2,
b, 2,
c, 1,

I know that unnest is not possible with cblite but maybe someone has an idea how to approach this result also in cblite!

Thank you!


#2

I don’t have a workaround for you, but we are working on UNNEST support for CBL (no schedule yet.)


#3

Thank you for the info, but wouldn’t it be possible to use smthg. like this

var searchQuery = QueryBuilder.SelectDistinct(
//SelectResult.Expression(Meta.ID),
SelectResult.Expression(Expression.Property(“Tag.Text”)).As(“Tag”))
//SelectResult.Expression(Function.Count(Expression.Property(“Tag.Text”)).As(“Count”)))
.From(DataSource.Database(context))
.Where(Expression.Property(“Type”).EqualTo(Expression.String(typeof(tt).Name)))
//.GroupBy(Expression.Property(“Tag.Text”))
.Limit(Expression.Int(int.MaxValue))

The problem is that the SelectResult cannot refer to sub property Tag.Text. Or can this maybe solved via a variable declaration?