Querying an array field that contains hashes in mongoDB?
I have a problem in fetching the data from database. I have a array type
column in mongodb database, in which i am saving hash type data in each
array index. I have to get data on the basis of that hash match from the
data base.
My data in database is saving like this
{
"_id" : ObjectId("521603970ff5fa4b47000018"),
"message_text" : "#cricket #badminton #sachin #tendulkar #ibl
#masterblaster #srt Cricketing world lights up IBL http://t.co/RWskRM2EQf
via @msncricket",
"source" : "<a href=\"http://twitter.com/tweetbutton\"
rel=\"nofollow\">Tweet Button</a>",
"status_id" : NumberLong("370521615638884352"),
"status_created_at" : "2013-08-22 17:53:31 +0530",
"user_id" : "31677680",
"screen_name" : "msncricket",
"name" : "MSN Cricket",
"followers_count" : 11515,
"friends_count" : 303,
"query" : [
{
"filterId" : "5215b40c0ff5fa111e000001",
"subfilterId" : "60728003610375795",
"type" : "keyword",
"source" : "twitter",
"monitoring_type" : false,
"search_type" : false,
"searchParameter" : "sachin",
"geo" : "india",
"language" : "en"
}
]
}
The query column is the array type column.
During searching i make a hash again form matching it like follows
query = {"filterId"=>"5215b40c0ff5fa111e000001",
"subfilterId"=>"60728003610375795", "type"=>"keyword",
"source"=>"twitter", "monitoring_type"=>false, "search_type" => false,
"searchParameter"=>"sachin", "geo"=>"india", "language"=>"en"}
@result = Statuses.where(query: query)
No comments:
Post a Comment