IBM Cloudant NoSql:为"字段创建QueryBuilder变量"

时间:2018-06-02 08:06:04

标签: java cloudant

对于java中的IBM Cloudant NoSql,我可以像这样创建一个QueryBuilder:

        QueryBuilder queryBuilder = new QueryBuilder(and(
                gt("Movie_year", 1960),
                eq("Person_name", "Alec Guinness"))).
                sort(Sort.desc("Movie_year")).
                fields("Movie_name", "Movie_year").
                limit(10);

不要让字段硬编码,而是希望它们是变量。我管理除"字段"。

之外的所有变量
        // variables
        selector = and(
                gt("Movie_year", 1960),
                eq("Person_name", "Alec Guinness"));
        Sort sort = Sort.desc("Movie_year");
        int limit = 10;
        int skip = 0;
        // create query Builder 
        queryBuilder = new QueryBuilder(
                selector).
                sort(sort).
                fields("Movie_name", "Movie_year").
                limit(limit).
                skip(skip);

如何制作"字段"变量?

1 个答案:

答案 0 :(得分:0)

在这里找到答案: https://github.com/cloudant/java-cloudant/blob/master/cloudant-client/src/main/java/com/cloudant/client/api/query/QueryBuilder.java

代码现在是:

    // variables
    selector = and(
            gt("Movie_year", 1960),
            eq("Person_name", "Alec Guinness"));
    Sort sort = Sort.desc("Movie_year");
    String[] field = {"Movie_name", "Movie_year"};
    int limit = 10;
    int skip = 0;
    // create query Builder 
    queryBuilder = new QueryBuilder(
            selector).
            sort(sort).
            fields(field).
            limit(limit).
            skip(skip);