Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php mongodb findOne return as object?

Tags:

php

mongodb

is it possible to return findOne result as object ..or it always return an array?

i found something about mongo.objects = 1 adding to php.ini ..but did not work for me.

can some one tell me more about this?

like image 625
xrado Avatar asked May 15 '26 16:05

xrado


1 Answers

I see no mentioning of the MongoDB PHP driver returning objects in either the API documentation or the tutorial. This is not really surprising as the official drivers stay close to the native bson document type used to represent documents.

There are however plenty of extra libraries that provide such mapping. Looking at the PHP Language Center page at mongodb.org, for example, I see a few libraries that provide direct object mapping, such as simplemongodb or mongodb-php-odm. They use their own API, so maybe just writing a simple conversion function from an array to an object instance yourself is more suited for you.

like image 84
catchmeifyoutry Avatar answered May 18 '26 04:05

catchmeifyoutry