I wanted to know how it's possible to do some simple CouchbaseLite queries.
I have a document named "test"
, with key-values "id": 5
and "name":"My first test"
.
I wanted to search following:
Database db = new Database("test_db");
using (var testDoc = new MutableDocument("test"))
{
testDoc.SetInt("id", 5)
.SetString("name", "My first test");
db.Save(testDoc);
}
Thanks!
Assuming I understood your question right that you want to fetch documents with a specific property value only if it exists, you can do something like this
var query = QueryBuilder.Select(SelectResult.expression(Meta.id),
SelectResult.expression(Expression.property("id")))
.From(DataSource.Database(db))
.Where(Expression.Property("name").NotNullOrMissing()
.And(Expression.Property("name").EqualTo(Expression.string("My first test"))))
Alternatively, if you know the Id of the document, it would be faster to do a GetDocument with the Id. Once you have the document, do a GetString on the name property. If it returns null, you can assume it does not exist.
Refer to the documentation on Couchbase Lite query fundamentals here.There are several examples. You may also want to check out API specs on NotNullOrMissing