node.js - Are MongoDB Stored JavaScript Procedures faster? -


lately i'm going deep in mongodb , i'm wondering stored javascript procedures. after reading blog entry pointbeing, got questions.

  • is real advantage store code in db? mean functions lookups documents, not adding numbers example pointbeing.
  • is faster javascript code access node.js side?
  • if queries stored in database, cached (and faster)?

i'm looking point of node.js development.

evaluating functions stored in db.system.js ("stored procedures", when call them that) deprecated. articles on db.eval shell function , the eval database command have "deprecated since version 3.0" warning , the article on server-sided javascript doesn't mention anymore. should avoid using it. 1 reason can not run javascript function when use sharding. when build application requires eval, prevent scaling in future. javascript functions undermine permission concept. need run admin, makes impossible establish sane permission system. problematic security standpoint considering server-sided scripts use user-provided data can potentially vulnerable arbitrary script injections.

the advantage of server-sided javascript runs on database server. reduces latency between application server , database server when need perform large number of queries. can same advantage opening mongo shell on database server , executing there.

the latency advantage relevant when perform multiple queries script. when have 1 query, still have latency when invoking script. gain nothing except unnecessary complexity.

there no additional caching or other optimization server-sided javascript. worse: reparsed , reinterpreted everytime run it. might slower javascript in application server.

further, many complex queries require script support implement find() can expressed using aggregation in cases far faster doing same find() , javascript because aggregation framework implemented in c++ , has access raw bson documents.


Comments