¿ù°£ Àα⠰Խù°

°Ô½Ã¹° 138°Ç
   
[MongoDB] Query
±Û¾´ÀÌ : ÃÖ°í°ü¸®ÀÚ ³¯Â¥ : 2015-06-09 (È­) 13:20 Á¶È¸ : 4968
±ÛÁÖ¼Ò :
                          

# mongo --host localhost
MongoDB shell version: 2.4.9
connecting to: 1XX.XX.XXX.36:27017/test

> help
db.help()                    help on db methods
db.mycoll.help()             help on collection methods
sh.help()                    sharding helpers
rs.help()                    replica set helpers
help admin                   administrative help
help connect                 connecting to a db help
help keys                    key shortcuts
help misc                    misc things to know
help mr                      mapreduce

show dbs                     show database names
show collections             show collections in current database
show users                   show users in current database
show profile                 show most recent system.profile entries with time >= 1ms
show logs                    show the accessible logger names
show log [name]              prints out the last segment of log in memory, 'global' is default
use <db_name>                set current database
db.foo.find()                list objects in collection foo
db.foo.find( { a : 1 } )     list objects in foo where a == 1
it                           result of the last line evaluated; use to further iterate
DBQuery.shellBatchSize = x   set default number of items to display on shell
exit                         quit the mongo shell

> show dbs;
admin (empty)
ceilometer 0.953125GB
local 0.078125GB

> use ceilometer
switched to db ceilometer

> show collections
alarm
alarm_history
event
meter
resource
system.indexes
system.users

> db.system.indexes.find()
{ "v" : 1, "key" : { "_id" : 1 }, "ns" : "ceilometer.system.users", "name" : "_id_" }
{ "v" : 1, "key" : { "user" : 1, "userSource" : 1 }, "unique" : true, "ns" : "ceilometer.system.users", "name" : "user_1_userSource_1" }
{ "v" : 1, "key" : { "_id" : 1 }, "ns" : "ceilometer.resource", "name" : "_id_" }
{ "v" : 1, "key" : { "_id" : 1 }, "ns" : "ceilometer.meter", "name" : "_id_" }
{ "v" : 1, "key" : { "user_id" : 1, "source" : 1 }, "ns" : "ceilometer.resource", "background" : false, "name" : "resource_idx" }
{ "v" : 1, "key" : { "resource_id" : 1, "user_id" : 1, "counter_name" : 1, "timestamp" : 1, "source" : 1 }, "ns" : "ceilometer.meter", "background" : false, "name" : "meter_idx" }
{ "v" : 1, "key" : { "project_id" : 1, "source" : 1 }, "ns" : "ceilometer.resource", "background" : true, "name" : "resource_project_idx" }
{ "v" : 1, "key" : { "resource_id" : 1, "project_id" : 1, "counter_name" : 1, "timestamp" : 1, "source" : 1 }, "ns" : "ceilometer.meter", "background" : true, "name" : "meter_project_idx" }
{ "v" : 1, "key" : { "last_sample_timestamp" : -1 }, "ns" : "ceilometer.resource", "sparse" : true, "name" : "last_sample_timestamp_idx" }
{ "v" : 1, "key" : { "timestamp" : -1 }, "ns" : "ceilometer.meter", "name" : "timestamp_idx" }
{ "v" : 1, "key" : { "_id" : 1 }, "ns" : "ceilometer.event", "name" : "_id_" }
{ "v" : 1, "key" : { "_id" : 1 }, "ns" : "ceilometer.alarm", "name" : "_id_" }
{ "v" : 1, "key" : { "_id" : 1 }, "ns" : "ceilometer.alarm_history", "name" : "_id_" }

> db.meter.find({'counter_name': 'cpu_util', 'resource_id' : "$INSTANCE_ID"}).sort({'timestamp': 3})

Example)
> db.meter.find({'counter_name': 'cpu_util', 'resource_id' : "5be2531a-18b0-410a-abb9-090800656d58"}).sort({'timestamp': 3})

>  var mapVolumes = function() {
...        emit(this.resource_id, this.counter_volume);
...    }
> var reduceAverage = function (key, values) {
...        var total = 0;
...        for (var i = 0; i < values.length; i++) {
...            total += values[i];
...        }
...        return total / values.length;
...    }
>  db.meter.mapReduce(mapVolumes, reduceAverage, { out: { merge: 'average_util' }, query: {'counter_name': 'cpu_util'}});
{
"result" : "average_util",
"timeMillis" : 273,
"counts" : {
"input" : 2663,
"emit" : 2663,
"reduce" : 105,
"output" : 6
},
"ok" : 1,
}

>  db.average_util.find()
{ "_id" : "0dc31dbb-47ea-4c50-a50f-16a0da6ad970", "value" : 4.736913871246464 }
{ "_id" : "2e7e2bbd-6661-4368-9f1a-ff3d272b5b81", "value" : 4.642959104484682 }
{ "_id" : "51ddc950-05ff-4101-bc58-dfc938cf6253", "value" : 4.76973059645138 }
{ "_id" : "58e32619-1b76-4e6d-9a12-9acb545c407c", "value" : 4.59 }
{ "_id" : "5be2531a-18b0-410a-abb9-090800656d58", "value" : 4.668502698020272 }
{ "_id" : "e1604924-d5eb-42ea-aac8-e98824d6c8aa", "value" : 4.58 }


À̸§ Æнº¿öµå
ºñ¹Ð±Û (üũÇÏ¸é ±Û¾´À̸¸ ³»¿ëÀ» È®ÀÎÇÒ ¼ö ÀÖ½À´Ï´Ù.)
¿ÞÂÊÀÇ ±ÛÀÚ¸¦ ÀÔ·ÂÇϼ¼¿ä.
   

 



 
»çÀÌÆ®¸í : ¸ðÁö¸®³× | ´ëÇ¥ : ÀÌ°æÇö | °³ÀÎÄ¿¹Â´ÏƼ : ·©Å°´åÄÄ ¿î¿µÃ¼Á¦(OS) | °æ±âµµ ¼º³²½Ã ºÐ´ç±¸ | ÀüÀÚ¿ìÆí : mojily°ñ¹ðÀÌchonnom.com Copyright ¨Ï www.chonnom.com www.kyunghyun.net www.mojily.net. All rights reserved.