发布
社区首页 >问答首页 >路过的大佬帮我看看,为什么我传递数据库ktmall_product和ktmall_classify的数据传递不出来?

路过的大佬帮我看看,为什么我传递数据库ktmall_product和ktmall_classify的数据传递不出来?

提问于 2024-10-21 20:20:59
回答 0关注 0查看 11

// 云函数入口文件

const cloud = require('wx-server-sdk')

cloud.init({ env:""}) 

const db=cloud.database();

const _=db.command;

const $=db.command.aggregate;

// 云函数入口函数

exports.main = async (event, context) => {

var type=event.type?event.type:""

// 获取销量排行榜

if(type=="top"){

return await db.collection("ktmall_product").where({

      checked:true

}).orderBy("sales","desc").limit(6).get()

}

if(type=="banner"){

return await db.collection("ktmall_product").where({

      checked:true,

      recommend:true

}).orderBy("_updateTime","desc").limit(4).get()

}

if(type=="category"){

// 查询首页的所有分类的列表

return await db.collection("ktmall_classify").aggregate()

.lookup({

    from:"ktmall_product",

    let:{

      class_id:"$_id",

      class_name:"$name"

},

    pipeline:$.pipeline()

.match(_.expr($.eq(["$parentid","$class_id"])))

.sort({

      orderid:-1

})

.done(),

    as:"prolist"

})

.end();

}

}

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档