2016-11-17 05:16
浏览 170

通过运行laravel raw mongodb查询选择最新记录

I'm trying ti get the latest inserted record of mongodb as a collection in laravel using moloquent (jessenger/mongodb) package.

But I can not figure out how to run this raw query in laravel :


I know the formate of raw query in laravel is :

$bcamps = Bcamp::raw()->find(my raw query);

But how can I return the last inserted record as a collection by running that raw query in laravel 5.3 ?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douyong4623 2016-11-17 06:17

    I've figured how to do that by selecting the last record and then get it as a collection to be able to update it.

    $bcamps = Bcamp::raw()->findOne([],['sort' => ['_id' => -1],'projection' => ['_id' => 1]]);
    $bcamps = Bcamp::where('_id', '=' , $bcamps->_id)->first();

    Hope to save some other people time.

    解决 无用
    打赏 举报

相关推荐 更多相似问题