sexta-feira, 20 de julho de 2012

Input de dados mongodb


Boa tarde!
Eu estou estudando mongodb e precisava fazer alguns testes com input de dados, e fiz um script simples para isso e funciona muito bem graças a nosso grande amigo BASH!
Espero que ajude alguém, abs.

#Link para o script:
https://github.com/abargiela/scripts/blob/master/Input_data_mongodb.sh

O script buscará o conteúdo em JSON e fará o input no mongo, segue uma saída simples.

Para visualizar o dado, no meu caso com meu banco chamando bancoteste e a collection colecaoteste


root@debian:~# mongo
MongoDB shell version: 2.0.6
> use bancoteste
switched to db bancoteste
> db.colecaoteste.findOne({"_id" : ObjectId("5009b85efbddf412d8e33c70")})
{
"_id" : ObjectId("5009b85efbddf412d8e33c70"),
"completed_in" : 0.212,
"max_id" : NumberLong("226389767435198464"),
"max_id_str" : "226389767435198464",
"next_page" : "?page=2&max_id=226389767435198464&q=linux",
"page" : 1,
"query" : "linux",
"refresh_url" : "?since_id=226389767435198464&q=linux",
"results" : [
{
"created_at" : "Fri, 20 Jul 2012 18:55:01 +0000",
"from_user" : "BlackBerryDev",
"from_user_id" : 65727873,
"from_user_id_str" : "65727873",
"from_user_name" : "Research In Motion",
"geo" : null,
"id" : NumberLong("226389767435198464"),
"id_str" : "226389767435198464",
"iso_language_code" : "en",
"metadata" : {
"result_type" : "recent"
},
"profile_image_url" : "http://a0.twimg.com/profile_images/2198932640/BlackBerry-Twitter_normal.jpg",
"profile_image_url_https" : "https://si0.twimg.com/profile_images/2198932640/BlackBerry-Twitter_normal.jpg",
"source" : "<a href="http://www.exacttarget.com/social" rel="nofollow">SocialEngage</a>",
"text" : "@marioboikov Thanks for your question. Support for Linux continues to be evaluated. I've added your request to the demand list.  ^AS",
"to_user" : "marioboikov",
"to_user_id" : 321267837,
"to_user_id_str" : "321267837",
"to_user_name" : "Mario Boikov",
"in_reply_to_status_id" : NumberLong("226038200148320256"),
"in_reply_to_status_id_str" : "226038200148320256"
},
.
. #Conteúdo omitido para não prolongar muito.
.

{
"created_at" : "Fri, 20 Jul 2012 18:54:15 +0000",
"from_user" : "North_Group",
"from_user_id" : 206944855,
"from_user_id_str" : "206944855",
"from_user_name" : "North Group",
"geo" : null,
"id" : NumberLong("226389576263036929"),
"id_str" : "226389576263036929",
"iso_language_code" : "en",
"metadata" : {
"result_type" : "recent"
},
"profile_image_url" : "http://a0.twimg.com/profile_images/1531683421/North_normal.jpg",
"profile_image_url_https" : "https://si0.twimg.com/profile_images/1531683421/North_normal.jpg",
"source" : "<a href="http://twitterfeed.com" rel="nofollow">twitterfeed</a>",
"text" : "Oracle Offers Free Software To Win New Linux Users (ORCL): Oracle has made an interesting offer to companies usi... http://t.co/M285wyD0",
"to_user" : null,
"to_user_id" : 0,
"to_user_id_str" : "0",
"to_user_name" : null
}
],
"results_per_page" : 15,
"since_id" : 0,
"since_id_str" : "0"
}