I have a database that I need to query and I need to get all of the results from an embedded document into an array so I can store them into variables in php. This is what a record of the mongodb looks like:
{
"_id" : ObjectId("987654321"),
"roles" : {
"988434fe-9ac8-390f-abb4-18e4a0cc83fd" : 9,
"fc261c0f-7124-3c81-89e8-ecb33771fe4e" : 9
},
"groupType" : "PUBLIC_GROUP",
"name" : "Service Tech Role",
"type" : "usergroup"
}
I can use the PHP function below to get all of the information from this document except for the embedded document data.
function getPerms()
{
$m = new MongoClient ("mongodb://localhost" );
$db = $m->test;
$collection = $db->roles;
$query = array( '_id' => $_SESSION['groupId'] );
$cursor = $collection->find( $query );
foreach ($cursor as $document) {
$_SESSION['object_permissions'] = $document["roles"];
}
}
What I need is for the "roles" data to be set in an array, like this:
988434fe-9ac8-390f-abb4-18e4a0cc83fd,9
fc261c0f-7124-3c81-89e8-ecb33771fe4e,9
What needs to be done to throw the embedded document into an array so I can store them as session variables in php?