@Test
  public void shouldBindAPojo() throws Exception {

    long nb = collection.count("#", new Friend("robert", "Wall Street", new Coordinate(2, 3)));

    assertThat(nb).isEqualTo(1);
  }
  @Test
  public void shouldBindManyParameter() throws Exception {

    long nb = collection.count("{name:#,address:#}", "robert", "Wall Street");

    assertThat(nb).isEqualTo(1);
  }
  @Test
  public void shouldBindParametersOnNestedFields() throws Exception {

    long nb = collection.count("{coordinate.lat:#}", 2);

    assertThat(nb).isEqualTo(1);
  }
  @Test
  public void shouldBindOneParameter() throws Exception {

    long nb = collection.count("{name:#}", "robert");

    assertThat(nb).isEqualTo(1);
  }
  @Test
  public void shouldBindListOfPrimitive() throws Exception {

    collection.insert("{index:1}");

    List<Integer> indexes = Lists.newArrayList(1, 2);

    long nb = collection.count("{index:{$in:#}}", indexes);

    assertThat(nb).isEqualTo(1);
  }
  @Test
  public void shouldThrowArgumentExceptionOnInvalidQuery() throws Exception {

    try {
      collection.count("{invalid}");
      fail();
    } catch (Exception e) {
      assertThat(e).isInstanceOf(IllegalArgumentException.class);
      assertThat(e.getMessage()).contains("{invalid}");
    }
  }
  @Test
  // https://groups.google.com/forum/?hl=fr&fromgroups#!topic/jongo-user/ga3n5_ybYm4
  public void shouldBindAListOfPojo() throws Exception {

    Buddies buddies = new Buddies();
    buddies.add(new Friend("john"));
    collection.save(buddies);

    collection.update("{}").with("{$push:{friends:#}}", new Friend("peter"));

    assertThat(collection.count("{ friends.name : 'peter'}")).isEqualTo(1);
  }
Пример #8
0
  @Override
  public void start(Stage stage) throws Exception {

    Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
    Scene scene = new Scene(root);

    stage.setScene(scene);
    stage.show();

    try {
      DB db = new MongoClient("localhost", 27017).getDB("UchCentre");

      Jongo jongo = new Jongo(db);

      MongoCollection studentss = jongo.getCollection("students");
      System.out.println("Найдено объектов: " + studentss.count());

      MongoCursor<Student> all = studentss.find("{}").as(Student.class);
      Student one = studentss.findOne("{name: 'Nurbek'}").as(Student.class);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }