const db = cloud.database()
const $ = db.command.aggregate
db.collection('orders').aggregate()
.lookup({
from: 'books',
let: {
order_book: '$book',
order_quantity: '$quantity'
},
pipeline: $.pipeline()
.match(_.expr($.and([
$.eq(['$title', '$$order_book']),
$.gte(['$stock', '$$order_quantity'])
])))
.project({
_id: 0,
title: 1,
author: 1,
stock: 1
})
.done(), //这个是干什么的?? 查了文档也没有任何说明....稀里糊涂的..不明白来问问
as: 'bookList',
})
.end()
.then(res => console.log(res))
.catch(err => console.error(err))
pipeline结束了。
https://developers.weixin.qq.com/community/develop/doc/000c2c09fa8e98816bf92dd0b56800?fromCreate=1