I am trying to use the value "project_id" from a JSON file to check it with the database if it is unique or not. I will add my code to tell in detail about my problem.
$jsonDecode = json_decode(file_get_contents(/path/to/json.json));
$project_id = $jsonDecode[0]->project_id;
$m = new MongoClient();
$db = $m->Database;
$collection = $db->test;
$cursor = $collection->findOne(array("project_id" => $project_id));
My JSON is formatted as follows:
[{"project_id": 66, "project_code": 14070169, "nr_samples": 96, "samples": [{EMBEDDED DOCUMENT WITH DATA}, {EMBEDDED DOCUMENT WITH DATA}, ..... GOES ON FOR A LONG TIME}]
I get the following error message:
ErrorException in UploadExcelFileController.php line 340: Undefined property: stdClass :: $ project_id
I don’t understand what is wrong here, because I use the same code for a similar formatted JSON file, and it works great! Can someone please help me? I just want to get the value "project_id" for the request.
UPDATE ...
. . project_id. JSON. , . !