I have a project in which I am creating a node API using express that will interface with a mongo DB atlas database and perform CRUD operation and send that data to the front end
In this part i am adding new users into the db which i have already created and collection named users now up to this point the code is all fine it connects successfully to the mongo db server and the API receives the JSON data with no issue the issue arises when i run the insert command its says that the insert is not supported however the .insertOne() method is the one mentioned in the MongoDB docs i have already tried saving the data as well using the .save method that didn't work either
Code: index.js ->
const express = require("express");const { MongoClient } = require("mongodb");const bodyParser = require('body-parser');const mongoose = require('mongoose');const app = express();app.use(bodyParser.raw({inflate:true, limit: '100kb', type: 'application/json'}));app.get("/", (req, res) => { console.log("MAIN");});app.listen(3001, () => { console.log(`Listening on port 3001`); });const url = "CONNECTION STRING";const client = new MongoClient(url);async function run() {try { await client.connect(); console.log("Connected correctly to server");} catch (err) { console.log(err.stack);}finally { await client.close();}}// Set up MongoDB connectionconst mongoUrl = 'MONGO URL DB';mongoose.connect(mongoUrl, { useNewUrlParser: true, useUnifiedTopology: true });const db = mongoose.connection; db.on('error', console.error.bind(console, 'MongoDB connection error:')); // Define User schema const userSchema = new mongoose.Schema({ _id: Object, username: String, password: String, name: String, email: String, phone_number: String});// Define User modelconst User = mongoose.model('User', userSchema);// Define POST endpoint for adding user data to MongoDBapp.post('/addUser', async (req, res) => {const { _id, username, password, name, email, phone_number } = JSON.parse(req.body); const user = new User({_id: _id,username: username,password: password,name: name,email: email, phone_number: phone_number }); console.log(JSON.parse(req.body)); db.collection("users").insertOne(user) .then(() => { console.log("ADDED TO DB SUCCESSFULLY!"); }).catch((err) => console.log(err));});run().catch(console.dir);