Arquivo da categoria: NoSQL

NoSQL Essencial – Um Guia Conciso para o Mundo Emergente da Persistência Poliglota

Nota do livro: 9.

Conteúdo
A necessidade de se lidar com volumes cada vez maiores de dados é um fator que motiva adotar uma nova classe de bancos de dados não relacionais, NoSQL. Os defensores dos bancos de dados NoSQL alegam que estes podem ser utilizados para criar sistemas com melhor desempenho, escalabilidade e mais fáceis de programar. O livro NoSQL Essencial é uma introdução concisa, porém completa, a essa tecnologia emergente em rápida ascensão.
Pramod J. Sadalage e Martin Fowler explicam como bancos de dados NoSQL funcionam e as formas pelas quais podem ser uma alternativa superior a um sistema tradicional de gerenciamento de banco de dados relacional. Os autores apresentam um guia rápido sobre os conceitos que você precisa conhecer para avaliar se os bancos de dados NoSQL são apropriados a suas necessidades e, se forem, quais tecnologias você deve explorar mais detalhadamente.

A primeira parte do livro concentra-se em conceitos básicos, incluindo modelos de dados sem esquema, agregados, novos modelos de distribuição, teorema CAP e map-reduce. Na segunda parte, os autores exploram questões de arquitetura e projeto associadas à implementação de NoSQL. Também apresentam casos de uso reais, que mostram os bancos de dados NoSQL em ação, e fornecem exemplos representativos utilizando Riak, MongoDB, Cassandra e Neo4j.

Além disso, ao trazer o trabalho pioneiro de Pramod Sadalage, NoSQL Essencial mostra como implementar projetos de forma evolutiva com migração de esquemas: uma técnica fundamental a ser utilizada em bancos de dados NoSQL. O livro termina descrevendo como o NoSQL se estabelece em uma nova era de persistência poliglota, em que diversos mundos de armazenamento de dados coexistem e os arquitetos podem escolher a tecnologia mais otimizada para cada tipo de acesso a dados.

Os tópicos examinados incluem:

– Avaliando para quais aplicações corporativas o NoSQL é (e não é) apropriado.

– Entendendo os ajustes na arquitetura associados à instalação de NoSQL.

– Utilizando o NoSQL para simplificar o desenvolvimento, evitando o problema do mapeamento de dados entre estruturas de dados na memória e sistemas de bancos de dados relacionais.

– Comparando os principais produtos NoSQL atuais.

– Explorando linguagens de consulta: CQL e Cypher.

– Gerenciando desempenho, confiabilidade, disponibilidade e recuperação.

– Utilizando o NoSQL em ambientes de desenvolvimento ágil.

– Aplicando o NoSQL em pesquisa/recuperação, gerenciamento de metadados, análise de texto, redes sociais, inteligência de negócio e serviços financeiros.

– Clusterizando bancos de dados NoSQL para lidar com problemas relacionados a grandes quantidades de dados com maior eficácia em relação aos custos.

– Como o teorema CAP se aplica ao raciocínio sobre consistência, disponibilidade e latência.

– Como o padrão map-reduce permite que as computações sejam paralelizadas em um cluster.

– Por que o NoSQL é um termo sem significado definido.

Rails + MongoDB Tutorial. Quickstart.

This is a Quickstart Tutorial for Rails + MongoDBRuby on Rails and MongoDB, a document based database, is a pretty good fit. It is very easy to integrate MongoDB with Rails. If you want to know how to install MongoDB, check out this article here: Installing MongoDB on Mac OS X Lion. Or this here: Installing MongoDB on Linux.

I assume you are familiar with Ruby on Rails ?

There are several GEMs to interact with MongoDB. I used the MongoID GEM. That worked pretty good for me. Just add this to your Gemfile:
[code type=ruby]
gem ‘bson_ext’, ‘1.6.0’  
gem ‘mongo’, ‘1.6.0’
gem ‘mongoid’, ‘2.4.6’

And run “bundle install” on your project, to load the GEM from the internet. And add the file mongoid.yml to your config folder:
[code type=ruby]
development:
    host: localhost
    database: myapp_dev

test:
    host: localhost
    database: myapp_test

production:
    host: localhost
    database: myapp_prod

This is the file where you are configuring the access to the database. If your mongodb instance is running locale you don’t need any username or password settings. Now you have to load the mongoid.yml file. You can do that by adding this line to your application.rb inside of the “class Application”.
[code type=ruby]Mongoid.load!(“config/mongoid.yml”)

Than just add a new Model to your project. For example “User”. That could look like that:
[code type=ruby]
class User
include Mongoid::Document
include Mongoid::Timestamps
field :username, type: String
field :firstname, type: String
field :llastname, type: String
field :email, type: String
filed :age, type: Integer
end

That’s it. You just have to include the Mongoid:Document.
[code type=ruby]include Mongoid::Document

And define your fields! Now you can create a new user and save it like that:
[code type=ruby]
user = User.new
user.username = “mike”
user.firstname = “Mike”
user.lastname = “Boby”
user.age = 44
user.save

Or make a query like that:
[code type=ruby]user = User.where( username: “mike”)

Check out the Criteria API for MongoID. That is pretty straight forward. Worked pretty well for me.

Rails + MongoDB Tutorial. Quickstart.

Robomongo RC10 brings support to SSL

We are very happy to announce the new Robomongo with SSL support:
Robomongo 0.9.0 RC10!

In this new release, Robomongo supports almost all SSL options that can be configured with mongo shell and Robomongo is probably the only MongoDB GUI program which can achieve this.

1. SSL Support

Robomongo (and MongoDB) supports TLS/SSL (Transport Layer Security/Secure Sockets Layer) to encrypt all of the network traffic. TLS/SSL ensures that network traffic is only readable by the trusted clients/servers.

Robomongo (and MongoDB) uses OpenSSL libraries. SSL encryption is done only with strong SSL ciphers with minimum of 128-bit key length for all connections.

Basic Connection to MongoDB with SSL Encryption

In order to connect to MongoDB server (mongod or mongos instance or MongoDB Atlas Cloud) which requires basic SSL encryption mode, configure a new Robomongo connection with “Address” (--host i.e. “mongodb.hostname”) on Connection tab and “CA Certificate” (--sslCAFile) on SSL tab to validate the server certificates as seen below:

With the configuration above Robomongo will connect to MongoDB server exactly like mongo shell connects with the command below:

mongo --ssl --host mongodb.hostname --sslCAFile /etc/ssl/ca.pem

Connection to MongoDB that Requires Client Certificates

In order to connect to MongoDB server (mongod or mongos instance or MongoDB Atlas Cloud) that requires CA-signed client certificate (an SSL certificate signed by a certificate authority), we will use Robomongo SSL options “CA Certificate” and “PEM Cert/Key” (and “Passphrase” if PEM key is encrypted). An example can be seen below:

The configuration above is equivalent to mongo shell command line connection below:

mongo --ssl --host mongdb.hostname --sslPEMKeyFile /etc/ssl/client.pem --sslCAFile /etc/ssl/ca.pem

Using Advanced SSL Options

We have two advanced options, let’s firstly see them on Robomongo and then explain them one by one:

CRL File (Blocking Revoked Client Certificates)

In order to disallow client connections with revoked certificates, we use CRL (Certificate Revocation Lists) file (i.e. crl.pem) option on Robomongo. This file contains a list of revoked certificates. This option corresponds to mongo --sslCRLFile option.

Hostname Validation

Mongo verifies that the hostname of MongoDB server – to which the connection attempted – matches the CN or SAN of the MongoDB’s PEM certificate file (--sslPEMKeyFile). If the hostname does not match the CN/SAN, mongo will fail to connect. It is possible (although not advised) to disable this validation with this option. This option corresponds to mongo --sslAllowInvalidHostnames option.

On Robomongo, we use “Invalid Hostnames” option to allow/disallow invalid host names.

Using Self-signed Certificates

Let’s start with an important suggestion from MongoDB documents for production uses of this option:

In general, avoid using self-signed certificates unless the network is trusted.

For production use, your MongoDB deployment should use valid certificates generated and signed by a single certificate authority.

Robomongo/MongoDB can use any valid SSL certificate issued by a certificate authority, or a self-signed certificate. If self-signed certificate is used, although the communications channel will be encrypted, there will be no validation of server identity. This configuration will prevent eavesdropping on the connection, however it will be vulnerable to a man-in-the-middle attack. Using a certificate signed by a trusted certificate authority will permit Robomongo/MongoDB to verify the server’s identity.

The example configuration above corresponds to mongo shell parameter below:

mongo --sslAllowInvalidCertificates

Troubleshooting SSL Connection Failures

Robomongo helps you with giving error details when SSL connection fails. This will save time since we will already have some idea about where to start investigation from.

Let’s explain this with a real example which can be seen below. Here we see the error is related to hostname mismatch; after a quick search (or even better, having read this blog), we find that mongo has a hostname validation feature. So we can start troubleshooting with learning more about MongoDB hostname validation rules. (Rule here is the hostname used in “Address” field on connection tab should be same as the hostname of the certificate used on SSL tab on Robomongo)

2. MongoDB Atlas Support


MongoDB Atlas is a cloud service for running, monitoring, and maintaining MongoDB deployments, including the provisioning of dedicated servers for the MongoDB instances.

After creating a new cluster on MongoD Atlas, you will be provided a similar connection string to connect your cluster:

mongo "mongodb://cluster0-shard-00-00-f8a5c.mongodb.net:27017,cluster0-shard-00-01-f8a5c.mongodb.net:27017,cluster0-shard-00-02-f8a5c.mongodb.net:27017/admin?replicaSet=Cluster0-shard-0" --ssl --username admin --password PASSWORD  

In the Robomongo screenshot below, an example is shown which connects to single server in replica set: cluster0-shard-00-00-f8a5c.mongodb.net:27017



Note: Currently Robomongo supports connection to single server of a replica set. Support for connection to Replica Sets is one of the most important features of next Robomongo release plan.

3. HighDPI Enhancements

In Robomongo RC10, for better High DPI support, we have implemented many fine-grained enhancements. And we have updated Robomongo to use latest Qt version Qt 5.7.

Some of the visible enhancements can be seen in the screenshot below.

Windows:
For Windows, it can be seen that icons look much better and text layout is also better handled on new Robomongo 0.9.0 RC10.

Ubuntu 16.04:

We see that with Robomongo RC10 the improvement is huge.

Note: On Ubuntu 16.04, there is a known issue related to Qt on high DPI screens where the issue is more noticeable after changing “Scale for menu and title bars” on Ubuntu display menu. We will publish a quick “How to” blog to solve this problem.

4. Other Highlights from New Release

  • For better security, we have updated our OpenSSL version to OpenSSL 1.0.1p which is the same version used by latest MongoDB 3.2.
  • We have updated Qt from Qt 5.5 to latest Qt 5.7. With this update there are many enhancements including cross platform High DPI support.

Roadmap

Our next major priority is to complete support for the most popular features:

  • SSH — Implemented
  • TLS/SSL — Implemented
  • Replica Sets — Planned for Next Release
  • User Management — Planned for Next Release