public void injectMembers(T instance) {
    try {
      String collectionName = this.collectionName;
      Jongo jongo = provider.get().get();
      MongoCollection collection = jongo.getCollection(collectionName);

      field.set(instance, collection);
    } catch (IllegalAccessException e) {
      throw new RuntimeException(e);
    }
  }
    /**
     * Instantiates a new mongo state service.
     *
     * @param params the params
     * @throws UnknownHostException the unknown host exception
     */
    public MongoStateProvider(final ObjectNode params) throws UnknownHostException {

      final MongoStateConfig config = MongoStateConfig.decorate(params);

      // initialization of client & jongo
      final MongoClient client = createClient(config.getHost(), config.getPort());
      jongo = new Jongo(client.getDB(config.getDatabase()));
      collectionName = config.getCollection();

      jongo.runCommand("{collMod: '" + collectionName + "', usePowerOf2Sizes : true }");
    }
  @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();
    }
  }
Beispiel #4
0
 public void runCommand(String command) {
   db.runCommand(command);
 }
 /**
  * returns jongo collection used by this state factory.
  *
  * @return the collection
  */
 public MongoCollection getCollection() {
   return jongo.getCollection(collectionName);
 }
 public MongoCollection GetMongoCollection(String dbType, String collection) {
   MongoDBConfig config = ConnectToMongoDB(dbType);
   MongoDBManager dbManager = new MongoDBManager(config);
   Jongo jongo = new Jongo(dbManager.db);
   return jongo.getCollection(collection);
 }