Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8865231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:27:04+00:00 2026-06-14T16:27:04+00:00

using MongoDB; my $content = $db->items->find(‘something’); my $json; while($content->next){ push the data into a

  • 0
 using MongoDB;

 my $content = $db->items->find('something');
 my $json;
 while($content->next){
           push the data into a $json
 }

where there is a way

 my @variables = $content->all;
 foreach (@variables){
    push the data into $json
 }

Is there any way i can convert directly push the data into json string;

and push the data into Mojolicious

$self->render(json => $json);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:27:06+00:00Added an answer on June 14, 2026 at 4:27 pm

    Wrote a small Mojo test script for it. Use

    $collection->find->all
    

    to get a list of all pages, not an iterator. Here’s the test:

    #!/usr/bin/env perl
    
    use Mojolicious::Lite;
    use MongoDB;
    
    # --- MongoDB preparation ---
    
    my $conn    = MongoDB::Connection->new; # create a MongoDB connection
    my $test_db = $conn->test;              # a MongoDB database
    my $tests   = $test_db->tests;          # a test collection
    
    # insert test objects
    $tests->remove();
    $tests->insert({name => 'foo', age => 42});
    $tests->insert({name => 'bar', age => 17});
    
    # --- Mojolicious::Lite web app ---
    
    # access the tests collection in a mojoy way
    helper mongo_tests => sub {$tests};
    
    # list all tests as JSON
    get '/' => sub {
        my $self = shift;
        $self->render(json => [$self->mongo_tests->find->all]);
    };
    
    # --- web app test ---
    
    use Test::More tests => 6;
    use Test::Mojo;
    
    my $tester = Test::Mojo->new;
    
    $tester->get_ok('/')->status_is(200);
    my $json = $tester->tx->res->json;
    is $json->[0]{name},    'foo',  'right name';
    is $json->[0]{age},     42,     'right age';
    is $json->[1]{name},    'bar',  'right name';
    is $json->[1]{age},     17,     'right age';
    

    Output:

    1..6
    ok 1 - get /
    ok 2 - 200 OK
    ok 3 - right name
    ok 4 - right age
    ok 5 - right name
    ok 6 - right age
    

    Note: I couldn’t use is_deeply to test the $json data structure because MongoDB adds OIDs. You’ll see them when you dump $json.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using mongodb 2.1 and how to translate this query into php db.counter.aggregate([ {
I am using MongoDB to store data. In my project I am connecting multiple
I am using mongoDB for a new project at work and I got into
I'm currently using MongoDB to record application logs, and while I'm quite happy with
I want to save content of page in mongodb using google chrome extension. What
I started using MongoDb in Scala via Casbah but cannot find on the Casbah
I have data something like this in mongodb { _id : ObjectId(4f0ee7310b09f7a254000001), createdAt :
I am using mongodb to store user's events, there's a document for every user,
Using MongoDB C# driver ( http://github.com/samus/mongodb-csharp ), seems that I'm unable to get the
Using MongoDB, I'm having trouble adding en element to an Array when the array

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.