Headline

MongoDB is an open-source Document-oriented database.

Description

MongoDB is a database which holds documents in the JSON-like Language:BSON format. A single database may consist of several collections in which documents are organized.

To query a database collection, Language:BSON objects are passed which are matched against collection entries. Certain object keys may also have a special use as operators. A typical query may look like this:

> db.employees.find({"salary" : {"$lt" : 2000}});

MongoDB also realizes Technology:Data Aggregation using an internal MapReduce implementation based on Language:JavaScript. This works on collection level by passing JavaScript functions for map and reduce steps to the database.

A simple example of aggregating statistical data may be the counting of tags attributed to a blog post or product in a database collection. If the collection contains documents of the form

{..., tags: ["foo", "bar", ...], ...}

A map function that emits a count for each tag might look like this:

> var mapfun = function() {
  this.tags.forEach(function(tag) {
    this.emit(tag, {"count" : 1});
  });
}

And a corresponding reduce function that emits the summed up tags will look like this:

> var reducefun = function(key, values) {
  var total = 0;
  values.forEach(function(value) {
    total += value.count;
  });
  return total;
} 

To run everything a MapReduce query is formulated:

> db.blogposts.mapReduce(mapfun, reducefun {"out" : "output"});

This will return an object containing data about the processed request and save all results to the new collection "output".

Spaces


Marcel Heinz edited this article at Wed, 05 Jul 2017 15:06:55 +0200
Compare revisions Compare revisions

User contributions

    This user never has never made submissions.

    User edits

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.