@Test public void shouldBindEnumParameter() throws Exception { Friend friend = new Friend("John", new Coordinate(2, 31)); friend.setGender(Gender.FEMALE); collection.save(friend); Iterator<Friend> results = collection.find("{'gender':#}", Gender.FEMALE).as(Friend.class).iterator(); assertThat(results.next().getGender()).isEqualTo(Gender.FEMALE); assertThat(results.hasNext()).isFalse(); }
@Test public void canFindWithOidNamed() throws Exception { /* given */ ObjectId id = new ObjectId(); LinkedFriend john = new LinkedFriend(id); collection.save(john); Iterator<LinkedFriend> friends = collection .find("{friendRelationId:{$oid:#}}", id.toString()) .as(LinkedFriend.class) .iterator(); /* then */ assertThat(friends.hasNext()).isTrue(); assertThat(friends.next().getRelationId()).isEqualTo(id); }
@Test public void canFindWithTwoOid() throws Exception { /* given */ ObjectId id1 = new ObjectId(); Friend john = new Friend(id1, "John"); ObjectId id2 = new ObjectId(); Friend peter = new Friend(id2, "Peter"); collection.save(john); collection.save(peter); Iterable<Friend> friends = collection .find("{$or :[{_id:{$oid:#}},{_id:{$oid:#}}]}", id1.toString(), id2.toString()) .as(Friend.class); /* then */ assertThat(friends.iterator().hasNext()).isTrue(); for (Friend friend : friends) { assertThat(friend.getId()).isIn(id1, id2); } }
@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(); } }
public static Result listBeers() { Iterable<Beer> all = beers.find().as(Beer.class); return ok(Json.toJson(all)); }