Relative Content

Tag Archive for node.jsmongodb

MongoDB data not being fetched on the frontend

import React, { useState, useEffect } from ‘react’; import Navbar from ‘../../components/navbar/Navbar’; import ‘./Chat.css’; function Chat() { const [messages, setMessages] = useState([]); const [input, setInput] = useState(”); useEffect(() => { const fetchMessages = async () => { try { const response = await fetch(‘http://localhost:3000/chats’); if (!response.ok) { throw new Error(‘Network response was not ok’); } […]

MongoDB server closed when POST requesting

I’m trying to test out a post request on Postman and I’m getting the 200 but is not reflected on Mongo and I’m getting an error in the console saying server is closed at Server.command.

Getting information from the MongoDB database in the form of printing pages

I want to implement сode in nodejs on how to select pages when printing pages for printing from the MongoDB database in such a way that they are cut or selected using a string of information and all are received together in an array. Like the following example:
Field of choice: 1, 4, 5-7, 8, 10-100
In this case, data numbers 1, 4, 5 to 7, 8, and 10 to 100 are extracted from all the data in the Mongo database.

monogdb not connecting properly with node

var express = require(‘express’); var router = express.Router(); var MongoClient = require(‘mongodb’).MongoClient /* GET home page. */ router.get(‘/’, function(req, res, next) { res.render(‘index’,{title: ‘Express’}); }); router.post(‘/submit’,function(req, res) { console.log(req.body) MongoClient.connect(‘mongodb://localhost:27017/’,function(err,client){ if(err) console.log(‘error’) else console.log(‘Database connected’) }) res.send(‘Form submitted successfully’); }); module.exports = router; Error showing in the terminal like below while submitting a form, terminal […]

Nodejs & mongodb

Ive taken all the async out of my code when connecting to mongo db

Mongodb multiply object on insertone

I am learning mongodb on node.js enviroment and when i add the same object with insertOne() function i see in compass that it’s generating new one with different _id. How to do prevent duplication in this scenario?