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).