3
find()方法的記錄。指定者()
查詢。在那個記錄中,有其他文件(表格)的關係id。我想獲取上面查找查詢結果的每條記錄的關係表記錄。 像:
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文檔獲取類別名稱的值。 我也嘗試獲取for each()之外的內部提取的類別名稱,但未得到temp數組的結果。