mongoDB の stream を使おうとしてサンプルコードを探すと意外と見つからないのでメモ var MongoClient = require('mongodb').MongoClient; function getIds (db, callback) { var condition = {}; // something var stream = db.collection('userActionLog').find(condition, {userId:1}).stream(); stream.on('error', function (err) { db.close(); return callback(err); }); var seen = {}, var ids = []; stream.on('data', function (doc) { if (!seen[doc.u
One question I often hear is “Why should I chose Mojolicious versus one of the other major Perl web frameworks?” While I have many answers to that question, I personally believe the most important difference is that Mojolicious is designed to be non-blocking. Many of you will have heard of Node.js. The reason that Node is popular is that it is designed to be non-blocking. By writing your webapp in
3T is halting development work on Robo 3T and we are setting the code repository to read-only. Users can continue to download the application but we recommend that they download Studio 3T Free to evaluate it. Robo 3T is deeply based on the Mongo shell client. This older client has been deprecated in MongoDB 5.0 and is not expected to be maintained in the future. The new Mongosh client is a Node-ba
Understanding MapReduce in MongoDB, with Node.js, PHP (and Drupal) (Note, some of the details in this post may be outdated. For example, MongoDB now supports Aggregation queries which simplify some of these use cases. However, the MapReduce concepts are probably still the same.) MongoDB’s query language is good at extracting whole documents or whole elements of a document, but on its own it can’t
あらゆるログを収集する 昨年あたりからfluentdという名前をよく耳にするようになりました。弊社での実際のプロジェクト活用が出てきています。そこで今回は備忘録としてセットアップからプラグインのインストール等の基本的な手順を紹介したいと思います。 セットアップ Amazon Linuxにインストールするためにリポジトリを設定して簡単インストールします。 $ sudo vi /etc/yum.repos.d/td.repo [treasuredata] name=TreasureData baseurl=http://packages.treasure-data.com/redhat/$basearch gpgcheck=0 yumでインストールにて自動起動設定します。 $ sudo yum install td-agent -y $ sudo service td-agent start
Wikimedia commons Yesterday we released the latest unstable version of MongoDB; the headline feature is basic full-text search. You can read all about MongoDB's full text search in the release notes. This blog had been using a really terrible method for search, involving regular expressions, a full collection scan for every search, and no ranking of results by relevance. I wanted to replace all th
間違った書き方 db.userlog.mapReduce(m,r, { query : query , scope : myfunc , out : {inline:1} } ); 正しい書き方 db.userlog.mapReduce(m,r, { query : query , scope : {myfunc : myfunc} , out : {inline:1} } ); 参考 MongoDB:MapReduceでscopeを使って関数を渡す方法 scopeに関しては本家マニュアルが非常にわかりにくいので、マニュアルを見るよりテストコードを見ましょう。 https://github.com/mongodb/mongo/blob/master/jstests/mr5.js
2011/04/27 MongoDB (via Mongoid) で 1:N のテーブルを MapReduce ! comments Rails で MongoDB を使ったアプリを作ってみてるわけですが、親子関係になってるテーブルでデータを集計したかったのでやってみました。 やりたかったことは、「プロジェクト」に「ユーザー」が「段階的」に「出資金」を出せるので、そのプロジェクト毎に出資金の合計値を出したい、とかそんな感じです。 テーブルはこんな感じ。 User (id, name, …) Project (id, name, …) Rank (id, amount, …) Investment (id, project_id, user_id, rank_id, …) この、「段階的」にを表すRankが曲者で、出資金額はここを見ないと取れないわけです。Investmentのrank_id
HEADS UP! This article was written for an older version of node. More up-to-date information may be available elsewhere. Article and Code updated by loarabia (Larry Olson). Article and Code updated by Toby Clemson In this article I hope to take you through the steps required to get a fully-functional (albeit feature-light) persistent blogging system running on top of node. The technology stack tha
はじめに タイトルの通り、自分の Twitter のタイムラインを全部 DB にぶち込んで後でニヤニヤする方法を紹介します。データの取得と保存は Node.js + MongoDB で行います。 これで MongoDB シェル上で以下の様な形で過去のツイートを検索できるようになります。 > db.posts.find(function(){ return this.text.match(/hoge/); }) 環境を整える タイムラインの取得には以前のエントリ(20 行で作る node.js による Twitter bot 作成講座 - 凹みTips)と同じ方法を使用し、Node.js を用いてStreaming API 経由でリアルタイムに取得します。DB には NoSQL で JavaScript と親和性の高い MongoDB を使い、Node.js からは Mongoose を利用
var command = { mapreduce:"communications", query:query, map:communicationCountMapFunc, reduce:communicationCountReduceFunc, out:'communications_mr_buf' }; var dbh = new DPH(Promise); //これはPromiseをDB対応させるラッパ mongoose.connection.db.executeDbCommand(command, dbh.handler(function (ret) { return ret.documents[0]; })); return dbh.promise;
shard環境中では、すべてのshardで並行してデータ処理が走ります。 (注意: 2010/2/2: shard内でのmap/reduceはペンティング中ですが、すぐに戻ります) map/reduce はデータベース [command] を経由して、呼び出されます。 データバースは一時的なコレクションを出力結果用に作成します。この一時的なコレクションは、クライアントのコネクションが閉じたとき、または明示的にdropされた場合削除されます。また、永続的な出力用のコレクション名を指定することもできます。 map と reduce ファンクションはJavaScriptで書き、サーバ上で実行されます。 コマンドの文法: db.runCommand( { mapreduce : <collection>, map : <map ファンクション名>, reduce : <reduce フ
こんにちは、ursmです。 今回はMongoDBの分散処理機構、MapReduceについてご紹介します。 MapReduceについてのごく簡単な説明 とにかくたくさん要素が入っている配列を考えてみます。 array = [1, 3, 5, 2, ...] この配列について、値がそれぞれ何回出現したか数え上げるにはどうしたらいいでしょうか。普通にぐるぐる回してカウントする、というのが思い付きますね。 counts = Hash.new(0) array.each do |i| counts[i] += 1 end counts #=> {1=>1034, 9=>996, 8=>962, ...} さて、もし要素が1億個あったら、はたまた1兆個あったらどうしましょうか。配列をいくつかに分けてそれぞれ数え上げ、その結果を足し合わせる…という風にすれば結果は一緒になるはずですね。それぞれの配列を数
RDBMSでは下記のようなSQLになると思います。(PostgreSQLでの例) SELECT to_char(timestamp, 'yyyy-mm-dd HH24'::text) AS ymdh ,count(*) FROM accesslog WHERE '2011-12-01' <= timestamp AND timestamp < '2011-12-02' GROUP BY ymdh ORDER BY ymdh ; MapReduceを実行する // 日本標準時を扱うためのユーティリティ関数 var JSTDate = function (str) { return ISODate(str + "T00+09:00"); }; // 日付範囲指定で対象を絞る。 // このように一時変数に記憶させておくと便利。 var query = { "timestamp" : { "$gt
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く