Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Many of the shell's helper functions are not available for server-side code execution. In the case of <code>printShardingStatus()</code>, it makes sense because there isn't a console to use for printing output and you'd rather have a string returned. Thankfully, you should be able to pull up the source of the shell function and reimplement it in your application (e.g. concatenating a returned string instead of printing directly).</p> <pre><code>$ mongo MongoDB shell version: 2.2.0 connecting to: test &gt; db.printShardingStatus function (verbose) { printShardingStatus(this.getSiblingDB("config"), verbose); } </code></pre> <p>So, let's look at the <code>printShardingStatus()</code> function...</p> <pre><code>&gt; printShardingStatus function (configDB, verbose) { if (configDB === undefined) { configDB = db.getSisterDB("config"); } var version = configDB.getCollection("version").findOne(); // ... } </code></pre> <p>Before turning all of the output statements into string concatenation, you'd want to make sure the other DB methods are all available to you. Performance-wise, I think the best option is to port the innards of this function to Java and avoid server-side JS evaluation altogether. If you dive deeper into the <code>printShardingStatus()</code> function, you'll see it's just issuing <code>find()</code> on the config database along with some <code>group()</code> queries.</p> <p>If you do want to stick with evaluating JS and would rather not keep this code within your Java application, you can also look into <a href="http://www.mongodb.org/display/DOCS/Server-side+Code+Execution#Server-sideCodeExecution-Storingfunctionsserverside" rel="noreferrer">storing JS functions server-side</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload