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

  • SEARCH
  • Home
  • 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 7819505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:58:50+00:00 2026-06-02T06:58:50+00:00

I’m working on a test-application for my master thesis where I’m trying to create

  • 0

I’m working on a test-application for my master thesis where I’m trying to create a very simple blog to show some of the advantages, disadvantages, features, and so on about using MongoDB.

I’ve created a small random post generator, which should produce an array with a post and everything it should contain for a blog post document inside MongoDB.

My array looks like this:

array
  'author' => 
    array
      'name' => string 'Shaine Coffey' (length=13)
      'email' => string 'Lars_Cherry@.com' (length=16)
  'post' => string 'Vivamus non lorem vitae odio sagittis semper. Nam tempor diam natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aenean eget magna. Suspendisse tristique neque venenatis lacus. Etiam bibendum fermentum metus. Aenean sed pede nec ante blandit viverra. Donec tempus, lorem fringilla ornare placerat, orci lacus vestibulum lorem, sit amet ultricies sem magna nec quam. Curabitur vel lectus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec dignissi'... (length=570)
  'date' => string 'Wed Mar 28 02:52:23 +0000 2007' (length=30)
  'rating' => int 0
  'comments' => 
    array
      0 => 
        array
          'name' => string 'Finn Hale' (length=9)
          'email' => string 'Magee_Huffman@.net' (length=18)
          'upVotes' => int 52
          'downVotes' => int 88
          'comment' => string 'augue malesuada malesuada. Integer id magna et ipsum cursus vestibulum. ligula. Aenean gravida nunc sed pede. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Proin vel arcu eu odio tristique pharetra. Quisque ac libero nec ligula consectetuer rhoncus. Nullam velit dui, semper et, lacinia vitae, sodales at, velit. Pellentesque ultricies dignissim lacus. Aliquam rutrum lorem ac risus. Morbi metus. Vivamus euismod urna. Nullam lobortis quam' (length=479)
      1 => 
        array
          'name' => string 'Axel Hall' (length=9)
          'email' => string 'Phillip_Simmons@.org' (length=20)
          'upVotes' => int 99
          'downVotes' => int 31
          'comment' => string 'mauris, aliquam eu, accumsan sed, facilisis vitae, orci. Phasellus dapibus ut, pellentesque eget, dictum placerat, augue. Sed molestie. Sed id risus quis diam luctus lobortis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Mauris ut quam vel sapien imperdiet ornare. In faucibus. Morbi vehicula. Pellentesque tincidunt tempus risus. Donec egestas. Duis ac arcu. Nunc mauris. Morbi non sapien molestie orci tincidunt adipiscing. Mauris molestie pharetra nibh. Aliquam '... (length=554)
      2 => 
        array
          'name' => string 'Laith Rowland' (length=13)
          'email' => string 'Graham_Nicholson@.net' (length=21)
          'upVotes' => int 15
          'downVotes' => int 73
          'comment' => string 'iaculis enim, sit amet ornare lectus justo eu arcu. Morbi Suspendisse eleifend. Cras sed leo. Cras vehicula aliquet libero. Integer in magna. Phasellus dolor elit, pellentesque a, facilisis non, bibendum sed, est. Nunc laoreet lectus quis massa. Mauris vestibulum, neque sed dictum eleifend, nunc risus varius orci, in consequat enim diam vel arcu. Curabitur ut odio vel est tempor bibendum. Donec felis orci,' (length=409)
  'tags' => 
    array
      0 => string 'War' (length=3)
      1 => string 'Freedom' (length=7)

Everything is random generated and for example the number of comments can vary and the same with the number of tags.

When I try to run the insert code into MongoDB I get the error Warning: MongoCollection::insert() expects parameter 1 to be an array or object

My Insert code looks like this:

for($i=0; $i<$n; $i++) {
    $post = BlogPosts();

    foreach ($postas $id => $item) {
        $collection->insert($item);
    }
}

I’ve of cause entered the MongoDB database and collection, like so (at the top of my PHP file):

$mongo = new Mongo();
$db = $mongo->insert_test;
$collection = $db->testing;

I’m suspecting that my error lies in how I create my array, but I can’t quite seem to find where the error is. When I’m encoding it into JSON, it’s validated correctly.

Another thing is, that when I look inside my MongoDB database “insert_test” inside the collection “testing” I get a lot of entries (documents), but they are “split” up, so for example the “tags” are in one document, the “comments” are in another, and so on.

Any help or suggestions to what my error is would be very appreciated.

Thanks
Sincere
– Mestika

  • 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-02T06:58:51+00:00Added an answer on June 2, 2026 at 6:58 am

    It looks very much as though you want to do

    $collection->insert($post);
    

    instead of:

    foreach ($postas $id => $item) {
       $collection->insert($item);
    }
    

    You don’t say what variable your var_dump shows. Is it of $post or is it of $item?

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

Sidebar

Related Questions

I'm working on embedding Python in our test suite application. The purpose is to
I have added some animation using jquery but it's not working: $('.test-container').click(function(){ $(this).css('background-color', 'rgb(119,
Background: Trevor was working on a test project solely for the purpose of trying
I am currently working on some test cases for my website. I've managed to
Working on a simple C program I'm stuck with an if test: int line_number
I'm working on some scripted GUI test for a windows C# .net app. I'm
I am working on a test application based on ASP.NET MVC. I am new
I have written a simple test application using asp.net mvc with C#. The application
I've uploaded a simple Ruby test application to Cloud Foundry that works on my
I am working on a PHP web application and some times I would like

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.