function calculateSimilarity(target, candidate) {
return 10;
}
var targetData={};
const db = uniCloud.database();
const res = await db.collection('need_post').aggregate()
.match({
postType: '工作'
})
. project({
_id: 1,
// tags: 1,
// metadata: 1,
// 调用相似度计算函数
similarity1:
function( {
body: calculateSimilarity,
args: [targetData, $$ROOT],
lang: "js"
}
)
})
.end();
//或
const res = await db.collection('need_post').aggregate()
.match({
postType: '工作'
})
. project({
_id: 1,
// tags: 1,
// metadata: 1,
// 调用相似度计算函数
similarity1:
$function( {
body: calculateSimilarity,
args: [targetData, "$$ROOT"],
lang: "js"
}
)
})
.end();
执行报错,不支持$function $$ROOT