Skip to content

Raw query that returns select fields #1227

@skeezus

Description

@skeezus

I'm using the query to organize places by location but return only a few columns/fields from each object in the collection. Based on my understanding of Mongo queries, the raw statement in the code below should work, but it returns an empty array. If I remove the name field it returns all the objects in the collection as expected, but not as desired.

There's several open issues on this question with no relevant responses. Even a "hey idiot, do this" would be nice.

$shops_sorted = Shop::raw(function($collection) use ($latitude, $longitude) {
                return $collection->find([
                    'status' => 'show',
                    'loc'    => [
                        '$near' => [
                                $longitude, 
                                $latitude
                                ]
                    ]
                ],
                [
                'name'     => 1
                ]
                );
            })->toArray();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions