What javascript methods are available in mongo? - mongo-shell

This is a general question and what i'm looking for here is a link to some resource.
Explanation:
I recently figured out how to run a mongo shell script (refer to this post: can't make basic mongo shell script with authentication) and in doing this i realized that the javascript methods available via the mongo shell are not the same as the ones i use in the browser. So my question is, where can i find a list of all available methods?
Please also note that i have already looked here: http://docs.mongodb.org/manual/reference/method/ While this is useful it is clearly not a complete list because it doesn't include the core javascript functionality such as for loops and methods like printjson().

The mongo shell is built on the JavaScript V8 engine so all basic JavaScript functionality available in Node.js is available in the Mongo shell (mongo university M101JS, week 1, lecture 8: Introduction to the Mongo Shell).
You've found the core functionality document which is fairly complete but does not explain how to use things like the admin commands. You can find a list of those here: http://docs.mongodb.org/master/reference/command/nav-administration/

Related

Is it possible to use a mongorc.js in MongoDB Compass?

I'd like to use my custom commands defined in a mongorc.js in MongoDB Compass. Is this possible?
Is it possible to use a mongorc.js in MongoDB Compass?
Compass does not support the mongo shell's notion of a mongorc.js startup file. The mongo shell is a lower level JavaScript console environment that provides some basic scripting capabilities for administrators; Compass is a desktop application which does not allow arbitrary execution of user-provided JavaScript.
However, if you want to customise Compass it is possible to Create Compass Plugins which are implemented as ReactJS modules. Compass plugins extend predefined roles in the Compass UI (such as the global header, database-level tabs, or collection-level tabs) and run in a much more limited security context as compared to the mongo shell.
Implementing a plugin is definitely more involved than a simple JavaScript include, but there are interesting possibilities if you want to tweak your admin UI (and perhaps share plugins with others).
For more information see: Plugin Tutorials and Compass Plugin Reference.

mongoDB as a file storage for Grails application

I've recently came across a need to store a higher amount of files in my application and because PaaS platform used to host the application provides mongo, I've would like to use it.
However because I'm quite inexperienced with mongo I have almost no idea what is the current state of mongo related plugins and tools for grails. What should I use? As I want to keep domain classes in SQL database and use mongo only to store related files (in this case it will be mostly a bunch of PDFs and text documents related to domain instance) the mongoDB ORM [1] plugin seems too "heavy". Unfortunately mongoDB ORM is probably the only mongo plugin for grails in active development at the moment.
In short, what would be the best plugin / library tool-set for this purpose? The closest thing that matches my need I've found is grails-mongo-files plugin [2], which is probably a little bit outdated with no further development.So far it seems that I will have to use mongo's java driver (or the gmongo wrapper) and write some storage service and taglib by myself (what is not necessary a bad thing).
[1] http://grails.org/plugin/mongodb
[2] https://github.com/quirklabs/grails-mongo-file
There is also the mongodb gridfs plugin. http://grails.org/plugin/mongodb-gridfs
One thing to consider is that gridfs effectively does two calls to mongo, one to retrieve file information and one to retrieve the file. So it might not be a good fit if your files are under 16 megabytes.
Here is a post on how to do this manually if you want to bypass plugins - http://jameswilliams.be/blog/entry/171

Zend MongoDB implementation

I am attempting to integrate Zend with MongoDB. I think I am almost there, but I need some help to complete the task. I am new to both zend and mongo, but reasonably experienced with PHP and MySQL.
Some details:
My Zend project is based on the skeleton tutorial at http://framework.zend.com/manual/2.0/en/user-guide/skeleton-application.html. This works fine on my computer, but is mysql-based.
I have installed MongoDB. I can write nosql on the command line and I can instantiate a MongoClient object in a PHP script, so those things seem to work and talk to each other.
I want to use mongo instead of mysql, and I have implemented Doctrine. I have no idea what Doctrine does, and I've been through several searches to try and find how to run mongo commands in zend. These facts lead me to conclude that I don't know what I'm doing.
So to the specifics of my question:
As I understand it, I should be instantiating a mongo object somewhere. If so, where should I put the instantiation in zend?
If not, presumably I need an existing instantiation of the mongo object to run various find/save commands from inside the model class, so if that's true, how do I access the existing mongo object?
Thanks for any help, and clarification questions are equally welcome.
Edited 13/12/2012 for clarification.
With the given answers it seems I am on the right track, and I can further clarify what I need:
Looking at the Doctrine Documentation linked below, I am still unclear where the document manager instantiation is supposed to occur. I would have expected it to go into a more generic location which is run on every page load. Also, most of the tutorials I find seem to refer to a file structure different given from the skeleton application, so when they say to put certain things in certain places, I'm not sure where they mean. For example, I keep seeing references to bootstrap files, but my only bootstrap files are in test directories.
My questions are these:
What code do I need to add into the indexAction function (which definitely responds when I go to the correct URL) if I simply want to print_r all the documents in a collection?
Do I need to add any other code elsewhere, if so where, and what code?
These are the different bits and what they do, working from the bottom up:
mongodb: data persistance
doctrineODM: Object Document Mapper. This maps mongo documents to php objects. It means you don't have to worry about doing any calls against mongo directly - you just work with plain old php objects. To use doctrineODM you need to define your model classes, and get the hang of using the DocumentManager - suggested, the Doctrine docs are quite good.
doctrineMongoODMModule: A module that integrates doctrine with zf2. The main thing it does is allow you to configure doctrine using zf2 config style, and gives you access to the DocumentManager via the zf2 ServiceManager. (I does quite a few other things too, but they are the main ones)
zf2 (mvc): Lets you define an interface so other things (like a web client) can manipulate your documents.
There is brilliant module doctrine-mongo-odm-module for mongoDB access.
Just add to composer.json
"require": {
....
"doctrine/doctrine-mongo-odm-module": "dev-master",
....
Doctrine documentation should help how to use it.

MongoDB helper applications

Are there any good applications that people use with the MongoDB database to make it easier? I'm using MongoVUE for looking at the data and querying data. Are there any other apps that I should know about? I'm thinking of using MongoDB from now on.
There's a MongoDB Admin UIs list you might find useful.
PHP Rock Monogo is an awesome web interface for querying that you should try out.
Download rockmongo-on-windows-v0.0.2.rar from http://code.google.com/p/rock-php/downloads/list, unzip the file and run rockstart.bat. Then, login as admin/admin in to the web interface.

Is there a better way to use javascript to import of data from an external URL into mongo db

The best I can come up with is to use the mongo shell "run" command to:
execute curl write to pull $someUrl to fs/tmp/myfile.ext
execute mongoimport to load fs/tmp/myfile.ext
I don't know the file system structure at compile time, so I am hoping the Gurus may know of a more direct way of loading data from a remote URL.
You can do this quite easily with any of the languages or drivers.
So if you use PHP + cURL + MongoDB, you can basically store the response right into MongoDB with all of the features of cURL.
The same should be true for most dynamic languages Python, Ruby, etc. If you use Node.js, the process should be quite similar. I only suggest the dynamic language for ease of scripting, but pretty much any of the supported drivers should allow you to do this.
Frankly storing it in a file is probably unnecessary.