I suggest giving this post a read
https://www.mongodb.com/compatibility/mongodb-laravel-integration
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I just learned MongoDB, I learned it by itself not with Laravel. Right now I'm trying to learn how to work with it on Laravel. I tried to search a bit for answers and tried it myself, but I feel like I'm not satisfied with what I'm doing.
I think my main question right now is how do we handle data from MongoDB on Laravel? Because it feels a bit of unnatural when it comes to working with JSON in PHP, not that I have experienced much myself, but compared to JS it feels more natural there.
So, to start what I do is:
// Get the collection instance.
$collection = DB::connection('mongodb')->getCollection('users');
// Get the data from the collection instance.
$result = $collection->find();
// Loop through the cursor and put the data into an array.
$users = [];
foreach($result as $user) {
array_push($users, $user);
}
// Now I have access to each of the document in the collection and I can do what I want with it.
return $users;
And to go back to my question, does it always have to be like this when handling MongoDB data?
I know that I could also use eloquent to build queries, but could I use the full potential of MongoDB if I go with this route?
I would really appreciate if someone could share other techniques or conventions when dealing with MongoDB.
I suggest giving this post a read
https://www.mongodb.com/compatibility/mongodb-laravel-integration
Please or to participate in this conversation.