Laravel-mongodb: Is it possible to set the ordering of an index?

Created on 4 Nov 2015  路  3Comments  路  Source: jenssegers/laravel-mongodb

Mongo allows you to specify a 1 or -1 order for indexes. Is this possible with laravel-mongodb?

Most helpful comment

Just look at the source! Taking a peek at the Blueprint::index method, it would seem you can just do $collection->index(['name' => -1]);

All 3 comments

/**
 * Simulate order by clause on the collection.
 *
 * @param  string  $key
 * @param  string  $direction
 * @return $this
 */
public function orderBy($key, $direction = 'asc')
{
    $descending = strtolower($direction) == 'desc';

    return $this->sortBy($key, SORT_REGULAR, $descending);
}

Thanks @cnhttpd. I'm familiar with the orderBy method, but that was not my question.

My question was dealing with Blueprint and creating an index on a collection.

Just look at the source! Taking a peek at the Blueprint::index method, it would seem you can just do $collection->index(['name' => -1]);

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Idnan picture Idnan  路  3Comments

pirmax picture pirmax  路  3Comments

imrannazirbhat picture imrannazirbhat  路  3Comments

phuocduy1988 picture phuocduy1988  路  3Comments

Vasiliy-Bondarenko picture Vasiliy-Bondarenko  路  3Comments