@Test public void indexCollationConversion() { Collation collation = collation(); com.mongodb.client.model.Collation driver = indexHelper.convert(collation); assertEquals("en", driver.getLocale()); assertTrue(driver.getCaseLevel()); assertEquals(UPPER, driver.getCaseFirst()); assertEquals(IDENTICAL, driver.getStrength()); assertTrue(driver.getNumericOrdering()); assertEquals(SHIFTED, driver.getAlternate()); assertEquals(SPACE, driver.getMaxVariable()); assertTrue(driver.getNormalization()); assertTrue(driver.getBackwards()); }
private BsonDocument getCommand(final ConnectionDescription description) { BsonDocument outputDocument = new BsonDocument(getAction(), new BsonString(getCollectionName())); outputDocument.append("sharded", BsonBoolean.valueOf(isSharded())); outputDocument.append("nonAtomic", BsonBoolean.valueOf(isNonAtomic())); if (getDatabaseName() != null) { outputDocument.put("db", new BsonString(getDatabaseName())); } BsonDocument commandDocument = new BsonDocument("mapreduce", new BsonString(namespace.getCollectionName())) .append("map", getMapFunction()) .append("reduce", getReduceFunction()) .append("out", outputDocument) .append("query", asValueOrNull(getFilter())) .append("sort", asValueOrNull(getSort())) .append("finalize", asValueOrNull(getFinalizeFunction())) .append("scope", asValueOrNull(getScope())) .append("verbose", BsonBoolean.valueOf(isVerbose())); putIfNotZero(commandDocument, "limit", getLimit()); putIfNotZero(commandDocument, "maxTimeMS", getMaxTime(MILLISECONDS)); putIfTrue(commandDocument, "jsMode", isJsMode()); if (bypassDocumentValidation != null && description != null && serverIsAtLeastVersionThreeDotTwo(description)) { commandDocument.put( "bypassDocumentValidation", BsonBoolean.valueOf(bypassDocumentValidation)); } if (description != null) { appendWriteConcernToCommand(writeConcern, commandDocument, description); } if (collation != null) { commandDocument.put("collation", collation.asDocument()); } return commandDocument; }
com.mongodb.client.model.Collation convert(final Collation collation) { return com.mongodb.client.model.Collation.builder() .locale(collation.locale()) .backwards(collation.backwards()) .caseLevel(collation.caseLevel()) .collationAlternate(collation.alternate()) .collationCaseFirst(collation.caseFirst()) .collationMaxVariable(collation.maxVariable()) .collationStrength(collation.strength()) .normalization(collation.normalization()) .numericOrdering(collation.numericOrdering()) .build(); }