我使用
查询来获取记录。在这些记录中,有其他文档(表)的关系ID。我想要获取上述查询结果中每个记录的关系表的记录。就像这样:find().toArray()
db.collection('serviceBooking').find({'request_to_sp_user_id': docs._id.toString()}).toArray(function (err, serviceBookingDocs) {
if (serviceBookingDocs.length) {
var asyncCalls = [];
serviceBookingDocs.forEach(function (bookingRecord, key) {
var temp = {};
temp.userDetails = {};
//Async call for getting the user details for all users
asyncCalls.push(function (callback) {
db.collection('userDetails').findOne({'user_id': new mongo.ObjectID(bookingRecord.booked_by_user_id)}, function (err, userDetailsDocs) {
db.collection('serviceBookingDetails').find({'serviceBookingId': bookingRecord._id.toString()}).toArray(function (err, bookingDetailsDocs) {
if (userDetailsDocs) {
if (bookingDetailsDocs.length) {
temp.bookingDetails = bookingDetailsDocs;
bookingDetailsDocs.forEach(function (bookDetailItems, key) {
db.collection('serviceCatalog').findOne({'_id': new mongo.ObjectID(bookDetailItems.catalogId), isDeleted: 0}, function (err, spCatalogs) {
db.collection('spServiceCatalog').findOne({'_id': new mongo.ObjectID(spCatalogs.serviceCategory)}, function (err, spServiceCatalogDocs) {
if (spCatalogs) {
(spServiceCatalogDocs)
spCatalogs.catalogName = spServiceCatalogDocs.name;
temp.bookingDetails[key].serviceCatalgs = spCatalogs;
} else {
spCatalogs.catalogName = null;
temp.bookingDetails[key].serviceCatalgs = spCatalogs;
}
callback(null, temp);
})
})
})
}
} else {
callback(null, null);
}
})
})
})
})
}
})
我尝试使用回调函数,但它没有从mainCategory文档中获取类别名称的值。 我还尝试在forEach()之外获取已获取的内部类别名称,但它并没有在temp数组中得到结果。