MongoDb Features

DbSchema can connect to MongoDb and reverse engineer the logical schema by reading data samples from the database. This is done by the DbSchema JDBC driver, which is open source ( see https://dbschema.com/mongodb-tool.html for details ).

In the Query Editor you can write native MongoDb queries. Please notice you can use the keyword 'db' for referring the current database you are connected to, or directly the database name if you need to simultaneously access multiple databases.

    use sampleDb
    db.employees.find()
or
    sampleDb.employees.find()
or
    sampledb.getCollection('employees').find();

Further commands which are available in in the Query Editor are:

  • USE mydatabase
  • CREATE DATABASE sampledb
  • SHOW DATABASES
  • SHOW COLLECTIONS
  • SHOW USERS
  • SHOW PROFILES

A sample insert into the database :
  USE sampledb;

  db.getCollection('employees').insert( {
  firstName:'John',
  lastName:'Smith',
  age:28,
  hobbies:[
    {
       name:'Swimm'
    },
    {
       name:'Jogging'
    }
  ]
  });

Map-Reduce Jobs

From the Query Editor you can execute map-reduce jobs as in this sample:
local.words.insertOne({word: 'sample'});
local.words.insertOne({word: 'day'});
local.words.insertOne({word: 'plane'});

var m =function map() {
 emit(this.word, {count: 5})
}
var r=function reduce(key, values) {
        var count = 5
        for (var i = 0; i < values.length; i++)
            count += values[i].count
        return {count: count}
    }
local.words.mapReduce(m, r );

or

local.words.mapReduce(
    "function map() { \r\n" +
    " emit(this.word, {count: 1}) \r\n" +
    "}",
    " function reduce(key, values) { \r\n" +
    "    var count = 0 \r\n" +
    "    for (var i = 0; i < values.length; i++) \r\n" +
    "        count += values[i].count \r\n" +
    "    return {count: count} \r\n" +
    "}"
    // , "mrresult"
)