Looping MongoDB objects using linux bash script
<p>I am trying to connect and select each object in a mongodb collection. Here is what I did.</p>

<pre><code>#!/bin/shmongo 104.198.195.35:27017/yelp --eval"db.getCollection('yelp').find({})"
for i in $( mongo104.198.195.35:27017/yelp --eval "db.getCollection('yelp').find({})" ); do
 echo item: $i
done
</code></pre>

<p>I am a noob in shell scripting.</p>

<p>Here is a sample of result of above script.</p>

<pre><code>item: "website_url"
item: :
item: "-"
item: }
item: ]
item: }
item: ],
item: "search_string"
item: :
item: "Best
item: gyms
item: ,
item: near
item: Los
item: Angeles,
item: CA
item: 90091,"
item: }
item: Type
item: "it"
item: for
item: more
</code></pre>

<p>My script is taking this as a string and not picking up the object</p>

<p>I want to pickup this</p>

<pre><code>{
"_id" : ObjectId("576826eb1a4f5d7fabf2dfe4"),
"search_url" : "http://www.yelp.com/search?find_desc=Gyms&amp;find_loc=Los+Angeles%2C+CA&amp;ns=1",
"search_url_id" : 1,
"search_group" : "YelpTest",
"Results" : [ 
    {
        "search_page_no" : 1,
        "page_results" : [ 
            {
                "rating" : "5.0",
                "name" : "BossFitnessLA",
                "tags" : "Trainers",
                "url" : "http://www.yelp.com/biz/bossfitnessla-beverly-hills",
                "rank" : "991",
                "contact_telephone" : "(310) 595-8811",
                "address" : "Beverly Hills, 415N Beverly Dr, Beverly Hills, CA 90210",
                "no_of_reviews" : "9",
                "website_url" : "-"
            }, 
            {
                "rating" : "5.0",
                "name" : "TK Fitness LA",
                "tags" : "Trainers",
                "url" : "http://www.yelp.com/biz/tk-fitness-la-west-hollywood",
                "rank" : "992",
                "contact_telephone" : "(323) 428-1445",
                "address" : "Hollywood, 828 N La Brea Ave, West Hollywood, CA 90038",
                "no_of_reviews" : "7",
                "website_url" : "-"
            }, 
            {
                "rating" : "2.5",
                "name" : "LA Fitness",
                "tags" : "Gyms, Trainers, Sports Clubs",
                "url" : "http://www.yelp.com/biz/la-fitness-monterey-park",
                "rank" : "993",
                "contact_telephone" : "(323) 346-6061",
                "address" : "416 South Atlantic Blvd Building B, Monterey Park, CA 91754",
                "no_of_reviews" : "192",
                "website_url" : "-"
            }, 
            {
                "rating" : "4.0",
                "name" : "Warner Bros Fitness Studio",
                "tags" : "Gyms",
                "url" : "http://www.yelp.com/biz/warner-bros-fitness-studio-burbank",
                "rank" : "994",
                "contact_telephone" : "(818) 954-4242",
                "address" : "Burbank, 4000 Warner Blvd Bldg 25, Burbank, CA 91522",
                "no_of_reviews" : "4",
                "website_url" : "-"
            }
</code></pre>