/** * Creates a collection with a given name and options. If the collection does not exist, a new * collection is created. * * <p>Possible options: * * <ul> * <li><b>capped</b> ({@code boolean}) - Enables a collection cap. False by default. If enabled, * you must specify a size parameter. * <li><b>size</b> ({@code int}) - If capped is true, size specifies a maximum size in bytes for * the capped collection. When capped is false, you may use size to preallocate space. * <li><b>max</b> ({@code int}) - Optional. Specifies a maximum "cap" in number of documents for * capped collections. You must also specify size when specifying max. * <p> * </ul> * * <p>Note that if the {@code options} parameter is {@code null}, the creation will be deferred to * when the collection is written to. * * @param name the name of the collection to return * @param options options * @return the collection * @throws MongoException */ public DBCollection createCollection(String name, DBObject options) { if (options != null) { DBObject createCmd = new BasicDBObject("create", name); createCmd.putAll(options); CommandResult result = command(createCmd); result.throwOnError(); } return getCollection(name); }
@Override public void savePlayer(GamePlayer gamePlayer) { service.submit( () -> { DBCursor cursor = collection.find(new BasicDBObject("uuid", gamePlayer.getUuid())); if (cursor.hasNext()) cursor.remove(); String json = GSON.toJson(gamePlayer); DBObject object = new BasicDBObject(); object.putAll((DBObject) JSON.parse(json)); collection.insert(object); }); }