Couchbase Lite + Xamarin + Search By Multiple Properties



We are looking at implementing Couchbase for an iPad App built with Xamarin.IOS. This is the first time we are digging into Couchbase and wanted to make sure that our use case is something that is doable with Couchbase.

Our main use case is to be able to query the data stored in the nosql database. Views seem like the only way to do this. It seems strange that the actual document cannot be queried directly like other nosql databases like MongoDB.

Say our data is in the following format:

We would want to query this data as follows:

  1. All records with DepartmentId = 1
  2. All records with StatusId = 2
  3. All records with DepartmentId = 1 AND StatusId = 2
  4. All records with DepartmentId = 1 OR StatusId = 2

From this presentation, I can see that we can create a view with a compound key. Something like [ DepartmentId, StatusId ]

But we are not able to query with just one part of the compound key. Couchbase seems to return results only if both the parts of the compound key are passed eg. [ 1, 2 ] This would return all records with department 1 & status 2.

Is this possible with Couchbase at all? Or should we be looking at some other solution. We dont want to go the SQL way because we have quite complex json objects and dont want to bother with converting it into tabular data. NOSQL is definitely the way ahead but is this the wrong NOSQL db for us?

C# that we tried :

        // Create the View
        var view = db.GetView("all-docs");
        view.SetMap((doc, emit) =>
            var keys = new List<object>();
            emit(keys, doc);
        }, "1");

        // Create Query
        var query = view.CreateQuery();
        List<Object> searchQuery = new List<Object>();
        List<Object> key = new List<Object>();
        // Add Query for Keys
        query.Keys = searchQuery;

        // Run Query
        var results = await query.RunAsync();