skip to Main Content

ReactJS, NodeJS, MongoDB, Backend

in index.js, const express = require("express") const mongoose = require("mongoose") const cors = require("cors") const CustomerModel = require('./models/Customer') const app = express() app.use(express.json()) app.use(cors()) mongoose.connect("mongodb://localhost:27017/customer") app.post("/login", (req, res) => { const {email, password} = req.body CustomerModel.findOne({email: email}) .then(user => {…

VIEW QUESTION

MongoDB aggregate merge condition

I have this below collection and I use MongoDB aggregation to acheive an output(where I aggregate all order line items for an order) and trying to merge into another collection(order). [ { "order_line_item_id": 1, "order_id": 100, "products": [ { "name":…

VIEW QUESTION

Javascript – Cannot read properties of null (reading 'collection'), this error is coming when submitting form. Unable to store data in database

in connection.js const mongoClient=require('mongodb').MongoClient const state={ db:null } module.exports.connect=function (done){ const url='mongodb://localhost:27017/' const dbname='shopping' mongoClient.connect(url,(err,data)=>{ if(err) return done(err) state.db=data.db(dbname) }) done() } module.exports.get=()=>state.db in product-helpers var db=require('../config/connection') module.exports={ addProduct:(product,callback)=>{ console.log(product) db.get().collection('product').insertOne(product).then((data)=>{ console.log(data); callback(true) }) } } I am unable to…

VIEW QUESTION
Back To Top
Search