我有两个收藏
带架构
{
a : Array,
b : ObjectID
}
Run Code Online (Sandbox Code Playgroud)
和 B 具有以下架构
{
x : 'string',
y : // some object schema
...
b : ObjectID
}
Run Code Online (Sandbox Code Playgroud)
我想使用 mongo 聚合在集合 B 中添加一个新字段,以仅包含使用 b 搜索的集合 A 中的 a。
我希望聚合后的值具有以下架构:
{
x : 'string',
newField : a // array from collection A
y : // some object schema
...
b : ObjectID
}
Run Code Online (Sandbox Code Playgroud)
只有 $lookup 不起作用,因为我不想要整个对象,并且合并将删除 _id 并合并我不想要的其他对象。
我有一个模块如下:
异步js
module.exports = async function (){
await func()
}
Run Code Online (Sandbox Code Playgroud)
索引.js
var asyncFun = require('async')
Run Code Online (Sandbox Code Playgroud)
如何像asyncFun()在index.js 中一样直接运行它?
我知道如何将这些函数作为中间件运行,但我想直接运行它。至于运行它,我需要调用await,并且await不能在异步内部调用。