Example usage for com.mongodb MapReduceCommand setJsMode

List of usage examples for com.mongodb MapReduceCommand setJsMode

Introduction

In this page you can find the example usage for com.mongodb MapReduceCommand setJsMode.

Prototype

public void setJsMode(final @Nullable Boolean jsMode) 

Source Link

Document

Sets the (optional) JavaScript Mode

Usage

From source file:org.mongodb.morphia.MapReduceOptions.java

License:Apache License

@SuppressWarnings("deprecation")
MapReduceCommand toCommand(final Mapper mapper) {
    if (query.getOffset() != 0 || query.getFieldsObject() != null) {
        throw new QueryException("mapReduce does not allow the offset/retrievedFields query ");
    }/*from w w w  .j a v  a 2 s  .  c om*/

    final DBCollection dbColl = inputCollection != null
            ? getQuery().getCollection().getDB().getCollection(inputCollection)
            : query.getCollection();
    final String target = outputCollection != null ? outputCollection
            : mapper.getMappedClass(resultType).getCollectionName();

    final MapReduceCommand command = new MapReduceCommand(dbColl, map, reduce, target, outputType,
            query.getQueryObject());
    command.setBypassDocumentValidation(bypassDocumentValidation);
    command.setCollation(collation);
    command.setFinalize(finalize);
    command.setJsMode(jsMode);
    command.setLimit(limit);
    command.setMaxTime(maxTimeMS, TimeUnit.MILLISECONDS);
    command.setOutputDB(outputDB);
    command.setReadPreference(readPreference);
    command.setScope(scope);
    command.setSort(query.getSortObject());
    command.setVerbose(verbose);

    return command;
}

From source file:org.springframework.data.mongodb.core.MongoTemplate.java

License:Apache License

private void copyMapReduceOptionsToCommand(Query query, MapReduceOptions mapReduceOptions,
        MapReduceCommand mapReduceCommand) {

    if (query != null) {
        if (query.getSkip() != 0 || query.getFieldsObject() != null) {
            throw new InvalidDataAccessApiUsageException(
                    "Can not use skip or field specification with map reduce operations");
        }//from  w ww .j  a  v a2  s . c  o  m
        if (query.getLimit() > 0 && mapReduceOptions.getLimit() == null) {
            mapReduceCommand.setLimit(query.getLimit());
        }
        if (query.getSortObject() != null) {
            mapReduceCommand.setSort(queryMapper.getMappedObject(query.getSortObject(), null));
        }
    }

    if (mapReduceOptions.getLimit() != null && mapReduceOptions.getLimit().intValue() > 0) {
        mapReduceCommand.setLimit(mapReduceOptions.getLimit());
    }

    if (mapReduceOptions.getJavaScriptMode() != null) {
        mapReduceCommand.setJsMode(true);
    }
    if (!mapReduceOptions.getExtraOptions().isEmpty()) {
        for (Map.Entry<String, Object> entry : mapReduceOptions.getExtraOptions().entrySet()) {
            ReflectiveMapReduceInvoker.addExtraOption(mapReduceCommand, entry.getKey(), entry.getValue());
        }
    }
    if (mapReduceOptions.getFinalizeFunction() != null) {
        mapReduceCommand
                .setFinalize(this.replaceWithResourceIfNecessary(mapReduceOptions.getFinalizeFunction()));
    }
    if (mapReduceOptions.getOutputDatabase() != null) {
        mapReduceCommand.setOutputDB(mapReduceOptions.getOutputDatabase());
    }
    if (!mapReduceOptions.getScopeVariables().isEmpty()) {
        mapReduceCommand.setScope(mapReduceOptions.getScopeVariables());
    }
}