Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-1536

Mongodb Shell: support for using it as a interpreter

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Trivial - P5 Trivial - P5
    • 1.7.0
    • Affects Version/s: None
    • Component/s: Shell
    • Labels:
      None

      I would love the possibility to do something like this:

      #!/usr/bin/mongo --interpreter
      db = connect("mongo.machine.host.com/mydatabase")
      [...]

      Doing this currently results in this (because of the first line which starts on #):
      $ ./test.mongo.js
      Mon Aug 2 14:59:54 SyntaxError: illegal character ./test.mongo.js:0
      failed to load: ./test.mongo.js

      For now, I have created a wrapper in bash to simulate the functionality (/usr/bin/mongointerpreter):
      #!/bin/bash
      file=`tempfile`.js
      cat $1 | grep -v '^#' > $file
      mongo --quiet $file
      rm -f $file

      Usage:
      #!/usr/bin/mongointerpreter
      db = connect("mongo.machine.host.com/mydatabase");
      print(db.sessions.find().count());

      I could probably manage to create a patch within the week if the feature sounds reasonable for you (a.k.a. if there's interest for it).

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            vilhelmk Vilhelm K. Vardøy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: