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 primary 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:
{
"Id":1,
"FirstName":"John",
"LastName":"Doe",
"DepartmentId":1,
"StatusId":2
}
We would want to query this data as follows:
- All records with DepartmentId = 1
- All records with StatusId = 2
- All records with DepartmentId = 1 AND StatusId = 2
- All records with DepartmentId = 1 OR StatusId = 2
From this presentation, http://www.slideshare.net/Couchbase/advanced-couchbase-lite 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 don't want to go the SQL way because we have quite complex JSON objects, and don't want to bother with converting it into tabular data. NOSQL is 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>();
keys.Add(doc["DepartmentId"].ToString());
keys.Add(doc["StatusId"].ToString());
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
key.Add(status);
key.Add(priority);
searchQuery.Add(key);
query.Keys = searchQuery;
// Run Query
var results = await query.RunAsync();
Lastly, any benchmarks on the performance of Couchbase Lite Queries if we are dealing with about 1000-5000 objects?