mardi, mars 23, 2010

Query Browser pour MongoDB

Comment chercher dans MongoDB des données (un peu comme mysql en ligne de commande) ?
Très simple utiliser irb et la lib ruby et suivre le tutorial: http://www.mongodb.org/display/DOCS/Ruby+Tutorial#RubyTutorial-AQuickTour
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'mongo'
=> true
irb(main):004:0> m = Mongo::Connection.new
=> #
irb(main):005:0> m.database_names.each { |name| puts name }
local
admin
my_db
=> ["local", "admin", "my_db"]
irb(main):008:0> db = Mongo::Connection.new.db("my_db")
=> #
irb(main):009:0> db.collection_names.each { |name| puts name }
people
system.indexes
=> ["people", "system.indexes"]
irb(main):011:0> coll = db["people"]
irb(main):012:0> coll.find.each { |item| puts item.inspect }
(...)
{"_id"=>ObjectID('4ba96c2360d99e0ba1000019'), "birthdate"=>nil, "phone_numbers"=>[],
 "last_name"=>"bar2", "login"=>"foobar2", "password"=>"secret", "first_name"=>"foo2"}
=> nil 
Technorati tags:

2 commentaires:

ViperGoy Blog a dit…

Thank you

ViperGoy Blog a dit…

Thank you