MongoDB
 SQL >> Database >  >> NoSQL >> MongoDB

Eseguire uno script JavaScript MongoDB dal driver Java

In MongoDB 3.4 e successivi, usa runCommand con un BasicDBObject contenente il comando eval.

final BasicDBObject command = new BasicDBObject(); command.put( "eval", String.format( "function() { %s return;}}, {entity_id : 1, value : 1, type : 1}).forEach(someFun); }", code ) ); Document result = database.runCommand(command);

Questo invia lo script al server come documento di comando.