JVM - collection.query.where()

Adds a new where clause to a query, which filters the data returned.

import io.nitric.Nitric;
import io.nitric.resources.CollectionPermission;
import io.nitric.api.documents.v0.Operator;

// A user class to store in the profiles collection
class User {
  String name;
  int age;

  public User(String name, int age) {
    this.name = name;
    this.age = age;
  }
}

public class Application {
  public static void main(String[] args) {
    var profiles = Nitric.INSTANCE.collection("profiles", User.class).with(CollectionPermission.Read);

    var profilesQuery = profiles.query().where("name", Operator.STARTS_WITH, "T");

    NITRIC.INSTANCE.run();
  }
}

Parameters

  • Name
    field
    Required
    Required
    Type
    String
    Description

    The document field to query.

  • Name
    operation
    Required
    Required
    Type
    Operator
    Description

    The query operation to perform.


    Valid values are: STARTS_WITH | EQ | NEQ | GTE | LTE | GT | LT.

  • Name
    value
    Required
    Required
    Type
    String or Int or Boolean
    Description

    The value to compare against.

Examples

A simple query

import io.nitric.Nitric;
import io.nitric.resources.CollectionPermission;
import io.nitric.api.documents.v0.Operator;

// A user class to store in the profiles collection
class User {
  String name;
  int age;

  public User(String name, int age) {
    this.name = name;
    this.age = age;
  }
}

public class Application {
  public static void main(String[] args) {
    var profiles = Nitric.INSTANCE.collection("profiles", User.class).with(CollectionPermission.Read);

    var profilesQuery = profiles.query().where("name", Operator.STARTS_WITH, "T");

    NITRIC.INSTANCE.run();
  }
}

Combining where clauses

var profileQuery = profiles
  .query()
  .where("firstName", Operator.EQ, "Drake")
  .where("age", Operator.GTE, 21)

See also