CNode

Mongodb中,aggregate不支持'$buyer'==xxx这种判断吗?代码如下

问答
JJarvisQJ发布于10 年前最后回复10 年前6 回复4215 浏览0 收藏
Consume.aggregate([
			{
				 $match:{
					  $or:[
						   {
								buyer:23
						   },
						   {
								seller:23
						   }
					  ]
				 }
			},
			{
				 $project:{
					  _id:1,
					  detail:1,
					  dealTime:1,
					  buyer:1,
					  money:{$multiply:['$money','$buyer'==23?-1:+1]}
				 }
			}
	   ])
		   .exec(function (err, consumes) {
				if(err) throw err;
				console.log(consumes)
				res.send(consumes)
		   })
		   
查看回复

回复 (6)

J
JarvisQJ#1·10 年前

这个编辑的时候有缩进,提交之后怎么没缩进了

J
JarvisQJ#2·10 年前
引用 JarvisQJ这个编辑的时候有缩进,提交之后怎么没缩进了

@qujinxiong 已解决,全选后加个tab键

O
o6875461#3·10 年前

要使用$condition进行判断

P
pauky#4·10 年前

可以参考下这个mongodb $cond

J
JarvisQJ#5·10 年前
引用 pauky可以参考下这个mongodb $cond

@pauky 解决了,非常感谢 money:{ $cond:{ if: { $eq: [ "$buyer", 23 ] }, then: {$multiply:['$money',-1]}, else: {$multiply:['$money',+1] }} }

J
JarvisQJ#6·10 年前
引用 o6875461要使用$condition进行判断

@o6875461 没有$condition,有$cond

参与回复
登录后即可参与回复。登录