úvod do
2000: rozmach
Memcache, Amazon Dynamo, Riak, Voldemort, GT.M
BigTable
Apache HBase, Apache Cassandra
Document base
MongoDb, CouchDb, CouchBase, Lotus notes
Full Text Search
Apache Lucene, Apache Solr, ElasticSearch
Graph Databases
neo4j, FlockDB
WHERE
state=
"CA:*"
WHERE
city=
"CA:San Francisco*"
class Entity_Profile extends FM_Model_Entity
{
protected $_data = array(
'profileId' => null,
'display' => '',
'about_me' => '',
'state' => '',
'education' => '',
...
);
...
}
class Mapper_Profile extends FM_Model_Mapper {
protected $map = array(
'profileId' => '_id',
);
public function insert(Entity_Profile $entity){
if(!$this->getDbTable()->isExist($entity->getPrimaryName(), $entity ))
$this->getDbTable()->insert($entity->toArray());
else return false;
}
...
}
class DbTable_Profile extends DbTable_Mongo {
CONST NAME = 'profile';
private $_collection = NULL;
public function __construct(){
parent::__construct();
$this->setCollection( self::NAME );
}
public function insert(array $data = array()){
return $this->getCollection()->insert($data);
}
public function update($filtre=array('_id' => NULL), array $data = array()){
return $this->getCollection()->update($filtre, array('$set' => $data));
}
...
}
class DbTable_Mongo {
const NAME = 'dbxyz';
protected $_db;
public function __construct(){
try {
$connection = new Mongo();
$this->_db = $connection->{self::NAME};
} catch (MongoConnectionException $e) {
$this->getLog()->log($e, Zend_Log::ERR);
die(...); // ? // throw new NosqlException(...)
}
}
...
//find - output Entity_Profile
$mapper = new Mapper_Profile();
$this->view->row = $mapper->find(array("profileId" => $id));
if(!isset($this->view->row)) {
// flashMsg
// redirect
}
//insert
$mapper = new Mapper_Profile();
$entity = new Entity_Profile($form->getValues());
if($mapper->insert($entity)) {
// flashMsg
// redirect
}
db.users.find(
{ $and: [
{ age: { $gt: 25, $lte: 50 } } ,
{ user_id: /^bc/ }
]
}
).sort( { user_id: -1 } ).limit(5).skip(10)
db.users.update(
{ status: "A" } ,
{ $inc: { age: 3 } },
{ multi: true }
)
require 'couchrest'
def foo
db = CouchRest.database!("http://..")
db.save_doc(doc)
def
require 'json/ext'
require 'couchrest'
@db = "http://..."
def foo
CouchRest.put(@db, doc)
def
IP | Traffic |
---|---|
192.168.1.11 | 3022 |
192.168.1.11 | 53022 |
192.168.1.13 | 955332 |
192.168.1.11 | 1024 |
192.168.1.13 | 952 |
IP | Traffic |
---|---|
192.168.1.11 | 3022 |
53022 | |
1024 | |
192.168.1.13 | 955332 |
952 |
IP | Traffic |
---|---|
192.168.1.11 | 57068 |
192.168.1.13 | 956284 |
function(doc, meta)
{
if (doc.ingredients)
{
for (i=0; i < doc.ingredients.length; i++)
{
for (j=0; j < doc.ingredients.length; j++)
{
emit([doc.ingredients[i].ingredient, doc.ingredients[j].ingredient, recipe.totaltime], null);
}
}
}
}
KEY | VALUE |
---|---|
["carrot", "rice", "1"] | NULL |
["carrot", "rice", "5"] | NULL |
["carrot", "pasta", "2"] | NULL |
["carrot", "rice", "25"] | NULL |
?startkey=["carrot","rice",0]&key=["carrot","rice",20]