Skip to content

How to use allowDiskUse: true? #541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Jul 11, 2015 · 15 comments
Closed

How to use allowDiskUse: true? #541

ghost opened this issue Jul 11, 2015 · 15 comments

Comments

@ghost
Copy link

ghost commented Jul 11, 2015

Help me,

How can I use 'allowDiskUse: true' in my model query?

@hackel
Copy link
Contributor

hackel commented Jul 30, 2015

Dupe of #491. Not supported, but would be easy to add as an option in \Jenssegers\Mongodb\Query\Builder::getFresh.

@chloealee
Copy link

Having the same issue! @hackel do you mean it'd be an easy fix on jenssegers end or would anyone be able to add code into their app for it to work? If the latter, could you explain how?

@hackel
Copy link
Contributor

hackel commented Sep 18, 2015

@chloealee You would have to fork it and modify the getFresh method. This is where MongoCollection::aggregate() is called, and allowDiskUse needs to be passed as an option there. If you don't want to bother with forking, you can just create a raw query with the raw() method.

@chloealee
Copy link

@hackel great, thanks!

@chloealee
Copy link

@hackel still having some trouble - tried to insert it into my raw query (below) but getting this error:

[MongoResultException] localhost:27017: exception: Unrecognized pipeline stage name: 'allowDiskUse'

        $duplicates = User::raw(function($collection) {
            return $collection->aggregate(
                [
                    '$group' => [
                        '_id' => ['email' => '$email'
                        ],
                        'uniqueIds' => [
                            '$addToSet' => '$_id'
                        ],
                        'count' => [
                            '$sum' => 1
                        ]
                    ]
                ],
                [
                    '$match' => [
                        'count' => [
                            '$gt' => 1
                        ]
                    ]
                ],
                [
                    'allowDiskUse' => true,
                    // 'cursor' => {}
                ]
            );
        });

do you know what I'm doing wrong?

@chloealee
Copy link

I see what I did wrong now! If anyone is having this issue too and needs an example, got this to work:

        $duplicates = User::raw(function($collection) {
            return $collection->aggregate(
                [
                    [
                        '$group' => [
                            '_id' => ['email' => '$email'
                            ],
                            'uniqueIds' => [
                                '$addToSet' => '$_id'
                            ],
                            'count' => [
                                '$sum' => 1
                            ]
                        ]
                    ],
                    [
                        '$match' => [
                            'count' => [
                                '$gt' => 1
                            ]
                        ]
                    ]
                ],
                [
                    'allowDiskUse' => true,
                ]
            );
        });

The issue was that it thought 'allowDiskUse' was a pipeline stage name so I had to separate it out even further from the query.

@ScottSpittle
Copy link

How would you go about passing in values from outside $duplicates, such as an array to compare.

@chloealee
Copy link

I think you'd want to do that after you find all of the $duplicates instead of passing through - just compare with the results in the array that gets returned.

@ScottSpittle
Copy link

Yeah, but the index filtering results before they are returned would be a lot quicker

@chloealee
Copy link

I'm not quite sure - sorry @ScottSpittle !

@ScottSpittle
Copy link

@chloealee No worries, Thanks anyway.

hackel pushed a commit to arcstone/laravel-mongodb that referenced this issue Sep 19, 2016
hackel pushed a commit to arcstone/laravel-mongodb that referenced this issue Sep 19, 2016
pi0 added a commit to moloquent/moloquent that referenced this issue Sep 28, 2016
* github.com:moloquent/moloquent:
  Allow setting custom options on a query [Fixes mongodb#541]
pi0 added a commit to moloquent/moloquent that referenced this issue Sep 28, 2016
@pi0
Copy link
Contributor

pi0 commented Sep 28, 2016

@sparrowbear @chloealee
This issue is now fixed on Moloquent Branch

Thanks to @hackel :)

@Puggers
Copy link

Puggers commented Apr 5, 2018

Not sure if I am in the right place for this, I am attempting to add the AllowDiskUse option invoking the options function, it doesn't seem to be handling it. Is AllowDiskUse usable outside of a raw query?

$tweets = Tweet::whereBetween('created_at.sec', dateToInt($request->get('startDate'), $request->get('endDate')))
            ->where(getTweets($request))
            ->orderBy('created_at.sec', 'desc')
            ->options(['AllowDiskUse' => true])
            ->paginate(10);

@dev-erem
Copy link

dev-erem commented Jul 5, 2018

@Puggers Can you please change AllowDiskUse to allowDiskUse?

@Puggers
Copy link

Puggers commented Jul 26, 2018

@amjad-eremnews The power of cases... yup that did it. Thanks!

mnphpexpert added a commit to mnphpexpert/laravel-mongodb that referenced this issue Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants