CBL 2.0 Query & Join Syntax Question

Hi,

we are working with CBL 2.0 .NET and seemingly I can’t figure out how to correctly use Joins in Queries.

Consider a database with two simple documents:

{
	"_id": "author_1",
	"name": "John Doe"
}

{
	"_id": "blog_post_1",
	"title": "Lorem Ipsum",
    "author": "author_1"
}

Since the documentation for Joins is not up yet, I tried to fiddle around and thought the following code should work (db being a reference to the CBL-Database):

var query = Query.Select(SelectResult.All())
			.From(DataSource.Database(db))
			.Joins(
			    Join.InnerJoin(DataSource.Database(db)).On(
                    Expression.Meta().ID.EqualTo(Expression.Property("author"))
                )
			);

IResultSet rows = query.Run();

But running that Query never finishes. It also throws no exception or such, so I don’t really know what I’m doing wrong. I also tried a couple of other things, like switching the “JoinOn”-Expression the other way around as well as joining on properties instead of meta-data. But the query always just never finishes.

So I hope someone could give me a pointer on what the correct API-Usage would be :).

As a side-question I would also ask if this is “the way to go”. NoSQL is still kind of new to us.
In reality we are talking about ~1-5 million documents of various “types” (i.e.: each “type” being akin to a SQL-Table and each document representing something akin to a SQL-Row-Entry and we put all documents from all tables into 1 bucket). Would you use N1QL-Joins like above in such a scenario or would it be faster/better to use GetDocument(authorId) instead? Or even use views instead?

Thanks & best regards,
Lars

But running that Query never finishes.

How many documents in this database? Are the CPU or disk heavily loaded? If not, can you pause the app and get a backtrace?

Your Join clause doesn’t specify which sources the ID and “author” properties belong to. I’m not actually sure what happens in that case; it depends on how SQLite handles the resulting translated query. You should use the “As” operator to name both the From source and the Join, and then use those names. (Sorry, I don’t know the exact CBL syntax for this. @pasin, can you help?)

But of course, even with this problem your query should still finish, with or without an error, so this looks like a bug…

The bucket currently contains 21 documents. So I’d expect a more or less instantaneous response ;).

Yeah, I was wondering on how to assign id and author to the respective “document-sets”, but couldn’t figure it out. If this is the problem and someone could help me out with the correct API-Usage, that would be super nice :).

It seems like a bug, as in “it should throw an error”. But since 2.0 is still in development I’d assume that wrong API-usage might not yet be handled correctly in some cases :).

[Edit]: When I’m back in the office and if this is a bug, I’ll post a bug-report. Last time I checked, symbol-server weren’t working though, so maybe no backtrace (but I’ll try again).

Hmmm I think it should be throwing an error without having the required AS clauses in the join. In lieu of proper documentation I suggest looking at the unit tests for some guidance. There is a test called TestJoin which should be useful.