dongzhuohan7085 2013-07-24 08:42
浏览 31
已采纳

MongoDB第一列+第二列> 2

I'm trying to develop myself about mongodb. and asking some question for two days.

yesterday, I've learned that "First column > Second Column". In mongodb I've made this like:

$hg = $coll_mac->aggregate(array(
                array('$match'=>array('sezon_kodu'=>$sezon, 'tarih'=>array('$lt'=>$time))),
                array('$project'=>
                    array(
                        'c'=>array('$cmp'=>array('$ft1','$ft2'))
                    )
                ),
                array('$match'=>array('c'=>array('$gt'=>0))),
                array( '$group' => array(
                    '_id' => '',
                    'total' => array('$sum' => '$c')
                        ))
            ));

Now, how can I write this? "Select records that (First column + Second Column)>2"

  • 写回答

1条回答 默认 最新

  • donglao7947 2013-07-24 08:44
    关注

    As I said last night, you ca use $add: http://docs.mongodb.org/manual/reference/aggregation/add/

    $hg = $coll_mac->aggregate(array(
        array('$match'=>array('sezon_kodu'=>$sezon, 'tarih'=>array('$lt'=>$time))),
        array('$project'=>
            array(
                'c'=>array('$add'=>array('$ft1','$ft2'))
            )
        ),
        array('$match'=>array('c'=>array('$gt'=>2))),
    ));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求指导ADS低噪放设计
  • ¥15 CARSIM前车变道设置
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存