where 构建动态条件 类似mybatis的<if test="true">?
where 构建动态条件 类似mybatis的<if test=“true”>
3 回复
这样?
var where = {
goodsName:{
$regex: “.*” + event.goodsName + “.*”,
$options: ‘i’
}
}
event.type && where.type = event.type;
event.tags && where.tags = event.tags;
var c = db.collection(‘goods’)
c = c.where(where)
// orderBy = [{field:‘view’,direction:‘desc’}, {field:‘price’,direction:‘desc’}, {field:‘cerateTime’,direction:‘desc’}]
for(var i in event.orderBy){
c = c.orderBy(event.orderBy[i].field, event.orderBy[i].direction);
}
c.skip(skip)
.limit(10)
.get()