ehoutsma / Codeigniter-MongoDB

Library for connection to MongoDB with PHP7
9 stars 14 forks source link

Select Field #5

Open Shelunagori opened 3 years ago

Shelunagori commented 3 years ago

### Suggestion

Using this library I was not able to get a single field from the MongoDB collection. I tried to execute a select query ( $this->mongo_db->select(array('foo', 'bar'))->get('foobar'); ). But it returns all the data of the document. For fixing this issue I went through the library I found an issue in the get method. In the get method, there is $options variable in that array we are passing 'projection'. we just need to remove [] of 'projection'.

or you can replace below mention line in the library.

Current Code ( Mongo_db.php -> get function line no 776 ) $options = ['limit'=>(int) $this->limit, 'skip'=>(int) $this->offset, 'sort'=>$this->sorts, 'batchSize'=>(int)$this->limit, 'cursorType'=>2, ['projection'=>$this->selects]];

Replace to

$options = ['limit'=>(int) $this->limit, 'skip'=>(int) $this->offset, 'sort'=>$this->sorts, 'batchSize'=>(int)$this->limit, 'cursorType'=>2, 'projection'=>$this->selects];