Search code examples
mongodb-javaspring-data-mongodb

Executing MongoDB Stored JavaScript/Procedures from Spring Java


I have few stored Javascripts in mongodb. I am using spring springframework.data.mongodb to access mongodb. How can i execute stored JavaScripts/procedures from this ?


Solution

  • found the solution.

    BasicDBObject obj = new BasicDBObject();
    obj.append( "$eval" , "stored_javascript_name()" );
    
    CommandResult t=mongoTemplate.executeCommand(obj);
    Object obj1=t.get("retval");