Category : mongodb

I want to get value of callback function. This is the DroneSeries Model: const mongoose = require(‘mongoose’) const Schema = new mongoose.Schema({ name: {type:String}, cat: {type:Number} }, {timestamps:true}) module.exports = mongoose.model(‘droneseries’, Schema) This is my code: const DroneSeries = require(‘../models/DroneSeries’) const droneSeries = DroneSeries.find((err, data) => { if (err) { console.log(‘Datas couldn’t get ‘, err) ..

Read more

I want to get datas from database (Mongodb) and write to EJS page. But I can’t get transfer data to a variable. My codes: const express = require(‘express’) const router = express.Router() const DroneSeries = require(‘../models/DroneSeries’) router.get(‘/technic-service’, (req, res) => { let droneSeriesData = "" const droneSeries = DroneSeries.find((err, data) => { if (err) { ..

Read more

I’m MEAN beginner…On submitting form I have: this.authService.createUserStep1( … this.companyForm.value.trucks ); After that I’m calling function this.authService.getTrucksByUserId(this.authService.getUserId()).subscribe(result => { this.trucksData = result.trucks; console.log(this.trucksData.length); for(var i = 0; i < this.trucksData.length; i++) { console.log(this.trucksData[i]._id); this.authService.addTruckDocs(arrayControl.at(i).value.TLic, arrayControl.at(i).value.Lic, arrayControl.at(i).value.CMRLic, this.trucksData[i]._id); } }); First function puts user info with trucks array. Imeddiately after that I want to fetch trucks ..

Read more

I am trying to get data from MongoDB and construct APIs to send data to my React App. Here’s my code for router and app.js: app.js const express = require(‘express’); const app = express(); const bodyParser = require(‘body-parser’); const mongoose = require(‘mongoose’); app.use(bodyParser.json()); //import routes const apiRoute = require(‘./routes/api’); app.use(‘/api’, apiRoute); //MONGODB CONNECTION mongoose.connect(‘mongodb://**[MY LINK ..

Read more