为了账号安全,请及时绑定邮箱和手机立即绑定

php链表Mongodb查询?

php链表Mongodb查询?

PHP
牛魔王的故事 2019-03-07 23:33:19
db.categoryGoods.aggregate([{$match:{categoryId:2841}} ,{$lookup:{from:"goods",localField:"goodsId",foreignField:"_id",as:"goods"}} ,{$project:{_id:0,goods:1}} ,{$unwind:"$goods"} ,{$match:{"goods.volume":{$lte:100}}} ,{$sort:{"goods.volume":-1,"goods._id":1}} ,{$skip:2} ,{$limit:5} ]) 昨天整了一天,没整出来,有没有php mongodb大神,帮忙把上面的mongodb命令翻译成php的执行语法?
查看完整描述

1 回答

?
紫衣仙女

TA贡献1839条经验 获得超15个赞

$sortMap = [
            ['position'  => 1, 'goods._id' => 1],
            ['goods.volume'  => -1, 'goods._id' => 1],
            ['goods.payPrice'  => -1, 'goods._id' => 1],
            ['goods.payPrice'  => 1, 'goods._id' => 1],
            ['goods.commissionRate'  => -1, 'goods._id' => 1],
            ['goods.createTime'  => -1, 'goods._id' => 1],
        ];
        if ($activeId <= 0 || !in_array($sortType, array_keys($sortMap))) {
            return $res;
        }
        $mongo = MongodbService::getInstance();
        $sort = $sortMap[$sortType];
        $offset = ($page -1) * $pageSize;
        $pipe = [
            ['$match'    => ['activeId' => intval($activeId)]],
            ['$lookup'   => ['from'  => 'goods', 'localField'=> 'goodsId', 'foreignField'=>'_id', 'as'=>'goods']],
            ['$project'  => ['_id'   => 0, 'goods' => 1, 'position' => 1]],
            ['$unwind'   => '$goods'],
            ['$sort'     => $sort],
            ['$skip'     => $offset],
            ['$limit'    => intval($pageSize)]
        ];
        $info = $mongo->selectDatabase('shopping')->selectCollection('activeGoods')->aggregate($pipe);
        foreach ($info as $value) {
            array_push($res['list'], $this->formatGoodsList($value["goods"]));
        }

mongodb链表查询 mongodb-$lookup

查看完整回答
反对 回复 2019-03-18
  • 1 回答
  • 0 关注
  • 357 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信