Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Raw:: queries returning nested BSONArray and BSONDocument instead of objects/arrays. #2407

Unanswered
Evinspam asked this question in Q&A
Discussion options

Hi,
I've just upgraded my laravel version from 5.7 to 8. When using a raw query, example:

$model = Foo::raw(function ($collection) use ($bar_id) {
	return $collection->aggregate([
		['$match' => [ "id" => $bar_id ]],
		['$lookup' => [
			'from' => 'seasons',
			"localField" => 'bar_id',
			"foreignField" => 'id',
			"as" => 'bar_details'
		]]
	]);
});

I used to get the properties of each item as arrays and objects, but they are now BSONArrays, BSONDocuments..

So if documents looked like this:

{
 id: 1, 
 somearray: ['foo', 'bar', 1,2],
 someobject: {foo: 'bar', ping: 'pong'}
}

and did something like $model[0]->somearray,

It now shows like this:

MongoDB\Model\BSONArray {#1853 ▼
 -storage: array:4 [▶]
 flag::STD_PROP_LIST: false
 flag::ARRAY_AS_PROPS: false
 iteratorClass: "ArrayIterator"
}

Just wondering how to convert it to it's proper state again.

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /