[mongodb] 스팀 잇 월별 가입자 수 변동사항

in #wdev7 years ago

steemdata에서 자료를 조회해 본 결과 아래와 같은 데이터를 볼 수 있었습니다.

참고로 1970년에 생성된 계정은 관리용 계정인 ( initminer, miners, null, temp ) 네요 ^^

스크린샷 2018-03-26 오후 5.29.33.png

스크린샷 2018-03-26 오후 5.29.45.png

nodejs sample

// require
const MongoClient = require('mongodb').MongoClient;
const f = require('util').format;
const assert = require('assert');

// DB 접속정보
const host = encodeURIComponent('mongo1.steemdata.com');
const user = encodeURIComponent('steemit');
const password = encodeURIComponent('steemit');
const port = 27017;
const database = encodeURIComponent('SteemData');

// 접속 URL 설정
const url = f('mongodb://%s:%s@%s:%d/%s', user, password, host, port, database);

// 서버에 접속하기 위한 connect
// url : 접속 url
// callback(err, client) : 접속 콜백
MongoClient.connect(url, (err, client)=>{

    // 오류처리 
    assert.equal(null, err);

    // 접속 성공 출력
    console.log("Connected correctly to server");

    // 월별 가입자 수 조회쿼리
    const query = [{
        "$group": {
            "_id": {
                "year": { "$substr": ["$created", 0, 4] },
                "month": { "$substr": ["$created", 5, 2] }
            },
            "count": { "$sum": 1 }
        }
    }, { "$sort": { _id: -1 } }];

    // 집합 쿼리 수행
    doAggregate(client, "Accounts", query, (docs) => {
        console.log(docs);
        client.close();
    });

});

// 집합 쿼리를 수행
// client : 접속 클라이언트
// collection : 컬렉션 명
// query : 집합 쿼리
// callback : 콜백
function doAggregate(client, collection, query, callback) {
    const times = new Date();
    const coll = client.db().collection(collection);
    coll.aggregate(query)
        .toArray(function(err, docs) {

            // 오류처리 
            assert.equal(err, null);

            // 콜백
            callback(docs);

            // 쿼리 수행시간 출력 
            console.log("elapsed time : " + (new Date() - times) / 1000 + " sec");
            console.log("counts : " + docs.length);
        });
}

Coin Marketplace

STEEM 0.20
TRX 0.16
JST 0.030
BTC 65895.15
ETH 2679.20
USDT 1.00
SBD 2.93