我有一个包含查询字符串的对象数组。我按照键循环遍历查询。查询按预期工作,但键值未被打印出来。
query = {
A: { code: { '$in': ['A'] }},
B: { code: { '$in': ['B'] }}
}
for (keyQuery of Object.keys(query)) {
console.log("outside",keyQuery );
testcollection
.find(query[keyQuery],{_id:0})
.then(data => {
console.log("inside",keyQuery);
});
}
当前的输出为
outside A
outside B
inside B
inside B
期望输出结果为:
outside A
outside B
inside A
inside B
我犯了什么错误