I have a script that is attempting to update a MongoDB collection with an xml response I've received from a server. I'm envoking simplexml_load_string() on the response. However, when updating the fields, it's adding an extra '0' key to the value I'm attempting to add. Here is the code:
$xml = simplexml_load_string($response);
if($xml->type == "reject") {
$status = $xml->type;
$message = $xml->message;
}
$update = array('$set' => array('status' => $status, 'response' => $message));
This is what I'm expecting:
{ "_id" : ObjectID("..."), "status" : "reject", "response" : "The message." }
However, here is the entry that is being saved in MongoDB:
{ "_id" : ObjectID("..."), "status" : { "0" : "reject" }, "response" : { "0" : "The message." } }
Any idea what is happening, or suggestions on how to fix it? Thanks!
$xml->type
and $xml->message
are probably objects, not strings. You might want to var_dump
it to see what it actually is and then convert it to a string.