0

having this weird issue while inserting to MongoDB using PHP. My insertion code is as follows :

$tyre = array("m" => '5', "i" => 'test.png');
$tyreCollection->insert(array($tyre),array('safe'=>true));

After insertion, I see the following in my DB :

{'_id' : ObjectId("856876876786867"),"0":{"m":'5','i':'test.png'}}

Why does my new array have a key of 0 ? I am expecting :

{'_id' : ObjectId("856876876786867"),"m":'5','i':'test.png'}

What am I doing wrong ?

2
  • 2
    not array($tyre) but only $tyre, at the momemnt You are inserting array(array(...)) Commented Apr 23, 2012 at 4:34
  • damm me ! Thanks a ton Bartosz :) Can you add this into your 'Answers' section so I can accept it ? Commented Apr 23, 2012 at 4:40

1 Answer 1

1

Insert only $tyre instead of array($tyre)

$tyreCollection->insert($tyre,array('safe'=>true));

Also always remember to dump variables with var_dump or print_r

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.