I have two collections of products and categories and I have both collections that have data products(152), categories(10). So, I tried to connect the DB to retrieve the data. First I call products collection data next call categories collection data using async-await functionality. But it gets the first categories of data and next product data. How to solve this issue anyone can give the answer.
product.js
async function product_data(collection) {
let mongodb = await MongoDB.connect(collection)
let result = await mongodb.findAll()
return result
}
module.exports.product_data = product_data
category.js
async function category_data(collection) {
let mongodb = await MongoDB.connect(collection)
let result = await mongodb.findAll()
return result
}
module.exports.category_data = category_data
app.js
const {product_data} = require("./product")
const {category_data} = require("./category")
async function updatedb() {
let product_data = await product_data("ecomm_product")
console.log(product_data)
let category_data = await category_data("ecomm_category")
console.log(category_data)
}
I got result
Its first print category_data after print product_data
Expected result
Its first print product_data after print category_data