0

我正在尝试使用 mongo-template 运行 js 文件。 在此处查看 StackOverFlow 线程

我正在尝试使用相同的代码库,根本没有改变。这对我不起作用。我在这一行得到异常:

scriptOps.register(new NamedMongoScript("echo", echoScript)); 

错误:

org.springframework.core.convert.ConverterNotFoundException:找不到能够从类型 [org.springframework.data.mongodb.core.script.NamedMongoScript] 转换为类型 [com.mongodb.DBObject] 的转换器

完成 StackTrace ...

org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:313) 在 org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:195) 在 org.springframework.core.convert。 support.GenericConversionService.convert(GenericConversionService.java:176) 在 org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:375) 在

4

1 回答 1

0
try{
         StringBuilder text = new StringBuilder();
        BufferedReader br = new BufferedReader(new FileReader(new File("C:\\piyush\\t.js")));
        try {
            while (true) {
                String line = br.readLine();
                if (line == null)
                    break;
                text.append(line).append("\n");
            }
        } finally {
            try { br.close(); } catch (Exception ignore) {

                System.out.println(ignore);
            }
        }

        ExecutableMongoScript echoScript = new ExecutableMongoScript(text.toString());
        Object ob=mongoOperation.scriptOps().execute(echoScript, "hello"); 
        System.out.println(ob);

t.js

function(x)    { return x; }

它会打印hello

于 2016-10-22T07:14:18.693 回答