Skip to content

Instantly share code, notes, and snippets.

@yteraoka
Last active December 26, 2015 02:59
Show Gist options
  • Save yteraoka/7082511 to your computer and use it in GitHub Desktop.
Save yteraoka/7082511 to your computer and use it in GitHub Desktop.
Ansible の fact を mongodb に突っ込んでみる
起動
sudo service mongodb start
$ mongo
MongoDB shell version: 2.4.6
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
> 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 wit h time >= 1ms
show logs show the accessible logger names
show log [name] prints out the last segment of log in memor y, '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 f urther iterate
DBQuery.shellBatchSize = x set default number of items to display on s hell
exit quit the mongo shell
> show dbs
local 0.078125GB
> use ansible
switched to db ansible
> db.facts.insert({ ... })
> db.facts.insert({ ... })
> db.facts.find().count()
2
> db.facts.findOne()["ansible_facts"]["ansible_processor_cores"]
6
> db.facts.find({"ansible_facts.ansible_system": "Linux"},{"ansible_facts.ansible_hostname":1})
{ "_id" : ObjectId("52650b20c53478b77449f8f3"), "ansible_facts" : { "ansible_hostname" : "host123" } }
{ "_id" : ObjectId("52650cb7c53478b77449f8f4"), "ansible_facts" : { "ansible_hostname" : "host456" } }
> db.facts.find({"ansible_facts.ansible_hostname": /host/},{"ansible_facts.ansible_hostname":1})
{ "_id" : ObjectId("52650b20c53478b77449f8f3"), "ansible_facts" : { "ansible_hostname" : "host123" } }
{ "_id" : ObjectId("52650cb7c53478b77449f8f4"), "ansible_facts" : { "ansible_hostname" : "host456" } }
http://docs.mongodb.org/manual/reference/program/mongoimport/#mongoimport
http://radengineers.blogspot.jp/2012/10/mongodb.html
http://minamitama-minamitama.blogspot.jp/2011/04/pythonmongodbinsert.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment