Hey Guys, 
I build my first Android App with Couchbase lite, now I don't know how I 
can Query Data like a Where Clause in SQL. The structure of my json files 
are like that. 
{
"id": 4001686390870,
"type": "foodstuffs",
"name": "Haribo Phantasia",
"tags": [
"Gummibears",
"sweets"
],
"ingredience": [
1,
2,
]}

Im SQL I just would want to know :

select type from table where type = 'foodstuffs'

How can I do this in my View ? I tried something in my code that looks like 
this
private String startQueryProduct() throws CouchbaseLiteException{

    com.couchbase.lite.View viewItem = database.getView(String.format(
            "%s/%s", designDocName, "QueryProduct"));
            if (viewItem.getMap() == null) {
        viewItem.setMap(new Mapper() {
            @Override
            public void map(Map<String, Object> document, Emitter emitter) {
                Object docName  = document.get("name");
                Object docType  = document.get("type");

                if (docType != null && docType.equals("foodstuffs" ) {
                    emitter.emit(docType.toString(),null);

                }
            }
        }, "1.0");
    }


    Query query = viewItem.createQuery();
    List<Object> l = new ArrayList<Object>(); 
    l.add("foodstuffs");
    query.setKeys(l);
     String productName = "" ;
    QueryEnumerator rowEnum = query.run();
    for (Iterator<QueryRow> it = rowEnum; it.hasNext();) {
        QueryRow row = it.next();

          productName += row.getDocument().getProperty("id")+"___"+row.
getDocument().getProperty("type")  +"___"+row.getDocument().getProperty(
"name")  + "_____"+ "\n" ;


        }
    return productName ; 

}



But in my App it shows me all my Items that are in my Database and doesn't 
select just the json files with type "foodstuffs".

On my Couchbase Server I made a View in my Shadow Bucket (I'm using Sync 
Gateway) named QueryProduct that looks like that 
function (doc, meta) {
if ( doc.type == "foodstuffs")
emit(doc.name, doc.id); 
}


on my Server everything works fine. Can't I just copy this in my Android 
Code to use this ?

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/49e70855-877d-49a4-a028-b5a0a5f0d3cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to