find를 사용하여 문서 집합에 대해 MongoDB를 이미 쿼리 할 수있는 node.js 모듈을 만들어 결과를 JSON으로 출력했습니다. 내 질문은 node.js가 비동기임을 알기 때문에이 쿼리 (항목)의 결과를 사용하여 MongoDB로 돌아가서 다른 문서 집합을 찾는 쿼리를 만드는 방법이다. 이 쿼리는 기본적으로 해당 직원의 정보가 포함 된 문서 (예 : firstName, lastName 등)를 쿼리하는 데 사용할 수있는 직원 ID 목록을 반환합니다. 그런 다음 결과를 JSON으로 출력하십시오. 첫 번째 쿼리는 기본적으로 특정 사용자가 볼 수있는 모든 직원을 제공합니다. 그런 다음 아래에서 볼 수 있듯이 직원 ID를 가져 와서 개인 정보가 포함 된 다른 문서 집합에 대한 쿼리를 수행해야합니다. 여기 Node.js 및 MongoDB 다른 쿼리 결과 사용
는이 개 문서의 스키마입니다 :직원
{
"_id" : ObjectId("5208db78ecc00915e0900699"),
"clientId" : 1,
"employeeId" : "12345",
"lastName" : "DOE",
"firstName" : "JOHN",
"middleName" : "A",
"badge" : "8675309",
"birthDate" : "10/12/1978"
}
사용자 직원이 액세스 할 수 있습니다 (사용자 캐시) 여기
{
"_id" : ObjectId("520920a99bc417b7c5e36abf"),
"clientSystem" : "SystemX",
"customerNumber" : "1",
"clientUserId" : "jdoe3",
"securityCode" : "authorize",
"employeeId" : "12345",
"creationDate" : "2013-Aug-12 13:51:37"
}
내 코드입니다 :
exports.employeeList = function(req, res) {
console.log(req.params);
var clientSystem = req.query["clientSystem"];
var clientUserId = req.query["clientUserId"];
var customerNumber = req.query["customerNumber"];
var securityCode = req.query["securityCode"];
if (clientSystem != null && clientUserId != null && customerNumber != null && securityCode != null){
db.collection('ExtEmployeeList', function(err, collection){
collection.find({'clientSystem': clientSystem, 'clientUserId':clientUserId, 'customerNumber':customerNumber, 'securityCode': securityCode}).toArray(function (err, items){
console.log(items);
res.jsonp(items);
});//close find
});//close collection
}//close if
else {
res.send(400);
}//close else
};//close function
제안 - 직원 ID를 기반으로 문서 집합을 검색하는 데 '$ in'을 사용하고 몽구스를 보면 조작 유형이 간단 해집니다. – WiredPrairie