0

i am using mongodb database.

DB::statement(DB::raw('set @row:=0'));
return \DB::connection('mongodb')->collection('users')->selectRaw('*, @row:=@row+1 as row')->get();

show error

(1/1) FatalErrorException Call to a member function prepare() on null

NobodyNada
  • 7,529
  • 6
  • 44
  • 51
  • 1
    You are trying to run a SQL statement on MongoDB. That does not work. Please read the documentation - [MongoDB CRUD Operations](https://docs.mongodb.com/manual/crud/) – Neil Lunn Jun 02 '18 at 11:08
  • Just pointing you at the duplicate of what you are attempting to actually do. You cannot get "row numbers" in a MongoDB result. The only "stupid" thing is forcing the whole collection into a single document and then getting the array index. This does not work in practicality because there is a 16MB limit on how much data a single document can have. – Neil Lunn Jun 02 '18 at 11:12

0 Answers0