devweb


CIS Home

DEVWEB home

Apache, HTML, CGI and PHP
Servlets/JSP
NodeJS
Gitlab
Mattermost
Microsoft SQL
MySQL
PostgresQL
MongoDB
Elasticsearch
Shibboleth

 

MongoDB

To use MongoDB you must first apply to Systems Support for MongoDB access.

Mongodb on devweb2019 is based on version 3.6 and so you need to use suitable mongodb client tools and libraries.

Here is some example php code showing how to authenticate to MongoDB which use the MongoDB PHP module:

<?php

$username="username";
$mng = new MongoDB\Driver\Manager("mongodb://${username}:password@devweb2019.cis.strath.ac.uk:27017/");

$listcollections = new MongoDB\Driver\Command(["listCollections" => 1]);
$res = $mng->executeCommand(${username}, $listcollections);
foreach ( $res as $c ) {
        print $c->name . "\n";
}

?>
See http://zetcode.com/db/mongodbphp/ for a more complete tutorial on PHP and MongoDB.

Here is another example of using the mongo shell:

mongo --host devweb2019.cis.strath.ac.uk:27017
use admin
db.auth("username", "password")
use username
show collections
exit

Here is another example of using the pymongo in python:

from pymongo import MongoClient
client = MongoClient('mongodb://username:password@devweb2019.cis.strath.ac.uk:27017/')
db=client.username
db.collection_names()

Accessing MongoDB from home

You will need to use a SSH tunnel to access MongoDB from outside the department.


e.g. ssh -2 -L 27017:devweb2019.cis.strath.ac.uk:27017 username@cafe.cis.strath.ac.uk

See this page for more details.

back to top