My Mongo DB code for inserting data is not working

I’ve tried several methods to use the mongodb insert methods, but it seems tobe non functional:

The code:

                       Bellow Code didn't work                            
`const dbConnect = require('./mongodb');

   const insertMany = async () => {
     try {
       console.log("insertMany function initiated");
       const db = await dbConnect();
       console.log('DB Connection details are as follows:n');
       console.log(db);

       const result = await db.insertMany({
         name: 'Asus Expert Book P2',
         brand: 'Asus',
         price: 1600,
         category: 'Notebooks'
       },{
         name: 'DELL XPS 13 Developer Edition',
         brand: 'Dell',
         price: 1800,
         category: 'Notebooks'
       },{
         name: 'System 76 16"',
         brand: 'System 76',
         price: 2100,
         category: 'Notebooks'
       },{
         name: 'Apple Macbook Pro Max 16"',
         brand: 'Apple',
         price: 1600,
         category: 'Notebooks'
       });

       return result;  Return the result of the insertManyion
     } catch (error) {
       console.error('Error insertManying data:', error);
       throw error;  Re-throw the error to handle it outside
     }
   }

   module.exports = insertMany;

    Call the function elsewhere
    Example:
    const insertManyFunction = require('./path/to/insertManyFunction');
    insertManyFunction().then(result => console.log('insertManyion result:', result)).catch(error => console.error('insertManyion error:', error));`

————-failed execution—————-
` const dbConnect = require(‘./mongodb’);

   const insertMany = async () => {
     console.log("insertMany function initiated");
     const db = await dbConnect();
     console.log('DB Connection details are as follows:n');
     console.log(db);

     const result = await db.insertMany({
       name: 'Asus Expert Book P2',
       brand: 'Asus',
       price: 1600,
       category: 'Notebooks'
     },{
       name: 'DELL XPS 13 Developer Edition',
       brand: 'Dell',
       price: 1800,
       category: 'Notebooks'
     },{
       name: 'System 76 16"',
       brand: 'System 76',
       price: 2100,
       category: 'Notebooks'
     },{
       name: 'Apple Macbook Pro Max 16"',
       brand: 'Apple',
       price: 1600,
       category: 'Notebooks'
     });

     return result;  Return the result of the insertManyion
   }

   module.exports = insertMany;`

  `const dbConnect = require('./mongodb');

  const insertMany = async () => {
    console.log("insertMany function initiated");
    const db = await dbConnect();
    console.log('DB Connection details are as follows:n');
    console.log(db);

    return db.insertMany({
      documents: [
        {
          name: 'Asus Expert Book P2',
          brand: 'Asus',
          price: 1600,
          category: 'Notebooks'
        },
        {
          name: 'DELL XPS 13 Developer Edition',
          brand: 'Dell',
          price: 1800,
          category: 'Notebooks'
        },
        {
          name: 'System 76 16"',
          brand: 'System 76',
          price: 2100,
          category: 'Notebooks'
        },
        {
          name: 'Apple Macbook Pro Max 16"',
          brand: 'Apple',
          price: 1600,
          category: 'Notebooks'
        }
      ]
    });
  }

  module.exports = insertMany;`

I need to know what’s going wrong here.. please help urgent.

I am expecting the code to be updating to following data base configuration:
“`

  const {MongoClient}= require ('mongodb');

  const url = 'mongodb:127.0.0.1:27017/e-comm';

  const client = new MongoClient(url);
  const database='e-comm';

  async function dbConnect(){
    console.log('Database connection is initiated')
    let result= await client.connect();
    let db=result.db(database);
    return db.collection('products');
    let response= await collection.find({}).toArray()
    console.log(response);
  }


   dbConnect().then((resp)=>{
   resp.find().toArray().then((data)=>{
     console.warn(data)
   })
   })
  console.warn(dbConnect());


      const main = async ()=>{
        let data = await dbConnect();
       data = await data.find().toArray();
       console.log(data);
     }


   main();


   const url = 'mongodb:127.0.0.1:27017/e-comm';

   const client = new MongoClient(url);
   const database='e-comm';
   async function dbConnect(){

     let result= await client.connect();
     let db=result.db(database);
     return db.collection('products');
     let response= await collection.find({}).toArray()
     console.log(response);
   }

  module.exports=dbConnect;
  ```

Here, commented code seems to be working well hence the DB is connected and fetch the response from database.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật