2015年9月9日水曜日

開発環境

MongoDBイン・アクション (Kyle Banker (著)、Sky株式会社 玉川 竜司 (翻訳)、オライリージャパン)のⅠ部(初めてのMongoDB)、3章(MongoDBを使ったプログラムの作成)、3.1(Rubyを通してみるMongoDB)、3.1.5(データベースコマンド)を Python で考えてみる。

コード(Emacs)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import pymongo

client = pymongo.MongoClient()
admin_db = client['admin']
dbs = admin_db.command({'listDatabases':1})

print(dbs)

入出力結果(Terminal, IPython)

$ ./sample1_5.py
{'ok': 1.0, 'totalSize': 251658240.0, 'databases': [{'name': 'local', 'empty': False, 'sizeOnDisk': 83886080.0}, {'name': 'mongodb-in-action', 'empty': False, 'sizeOnDisk': 83886080.0}, {'name': 'tutorial', 'empty': False, 'sizeOnDisk': 83886080.0}]}
$ ipython
Python 3.4.3 (default, Aug 26 2015, 18:29:14) 
Type "copyright", "credits" or "license" for more information.

IPython 4.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import pymongo

client = pymongo.MongoClient()
admin_db = client['admin']
dbs = admin_db.command({'listDatabases':1})


In [2]: 
In [2]: 
In [3]: 
In [4]: 
In [5]: 
In [5]: dbs
Out[5]: 
{'databases': [{'empty': False, 'name': 'local', 'sizeOnDisk': 83886080.0},
  {'empty': False, 'name': 'mongodb-in-action', 'sizeOnDisk': 83886080.0},
  {'empty': False, 'name': 'tutorial', 'sizeOnDisk': 83886080.0}],
 'ok': 1.0,
 'totalSize': 251658240.0}

In [6]: quit()
$ 

0 コメント:

コメントを投稿