Search Posts

Category: mongodb

can,t able to save hindi unicode character into mongodb for multiple fields

can,t able to save hindi unicode character into mongodb for multiple fields const WordsSchema = mongoose.Schema({ word1:{ type: String, required: true, language_override:”Hindi” }, word2:{ type: String, required: true, language_override:”Hindi” } }); on setting language_override i able to save word1 but it don,t save word2 Code on angular side is -> <input class=”form-control keyboardInput” id=”Hindimeaning” [(ngModel)] =”word1″ name=”word1″ placeholder=”Meaning in Hindi 1″ type=”text”> <input class=”form-control keyboardInput” id=”Hindimeaning2″ [(ngModel)] =”word2″ name=”word2″ placeholder=”Meaning in Hindi 2″ type=”text”> how […]

to delete data from mongodb using angularjs and nodejs

// remove user function() $scope.removeUser = function(_id,$index) { alert(‘Are you sure you want to delete?’); var data={productid:_id}; alert(data.productid); $http({ url: ‘http://localhost:3100/manage-product’, method: ‘POST’, data: data.productid, }).success(function(res) { console.log(‘another success’); }, function(error) { console.log(error); alert(‘here’); }); } request body is empty at node.js,why is it so.? node.js‘/manage-product’, function(req, res){ console.log(‘I received another get request’); console.log(req); var removeproducts = function(db, callback) { console.log(“entered”); db.collection(‘users’).deleteOne({_id : ObjectId(req.body.productId)}, function(err, results) { console.log(‘product deleted’); callback(); }); }; }); This […]

Not able to add new property to mongoose result

I have a userDetail document which has all the details regarding the user. I have a login document which has a time of the first login which I want to add to the result of the userDetails. Here is the Code on my Nodejs server application. Login.findOne({},(err,loginDetails)=>{ if(!err){ if(loginDetails===null){ //user is not already logged in //saving login new details let newLogin=new Login();; newLogin.userType=user.userType;,loginDetailsAfterSaving)=>{ if(err){ res.status(500).send(err); } let token=jsonwebtoken.sign(user.toJSON(),”example1″); res.status(200).json({token:token}); }); } for adding […]

How to fetch value from Json Array

Here is JSON array coming from server and i want to fetch values from this array and I’m unable to do so.. posts: {posts[0][comments][0][downCounter]: “0”, posts[0][comments][0][upCounter]: “4”, posts[0][comments][0][commentBy]: ” NJ”, posts[0][comments][0][commentValue]: “nows its time”, posts[0][comments][0][commentId]: “1”} Source: AngularJS

http.get doesn’t work inside a for loop when fetching data from mongo using express

I am trying to fetch data from mongodb using express to angular inside a for loop. I can access data inside this get instance but not outside of it. Here is my code var daily_jobs=[]; $http.get(mongodUrl).then(function(response) { var allMachinename =; daily_jobs=[]; for(var i = 0;i<allMachinename.length;i++){ $scope.masch_name.push({name:allMachinename[i].name,id:allMachinename[i].id,daily_jobs:[]}); $http.get(mongodUrl+’getmaschdata/’+$scope.input_id+’/’+allMachinename[i].id).then(function(jobs) { if( > 0){ daily_jobs=; } console.log(daily_jobs[0].job_name); },function(err){ console.log(err); }); $scope.masch_name[i].daily_jobs= daily_jobs; } },function(err){ //console.log(err); }); The variable daily_jobs is global, but when I want to […]

Angularjs not saving data in particular field

I am trying to save data in name field, but despite the POST request running without any error, mongodb collections shows only _id and _v updated. In short, I am unable to save data in a particular field. VIEW: <div id=”bookslist” class=”row” ng-controller=”poster as po”> <form ng-submit=”po.createTodo()”> <div class=”col-sm-7 form-group”> <label for=”” class=”col-sm-2″>Name</label> <input type=”text” name=”” value=”” placeholder=”” ng-model=”” class=”col-sm-6″> </div> <div class=”col-sm-7 text-right”> <button type=”submit” class=”btn btn-sm btn-success”>Submit</button> </div> </form> </div> Controller: app.controller(‘poster’, [‘$http’, […]

how to get mongoDB data to Angular 4 form

I need to use a get-request to retrieve mongo db data and pass it to my angular 4 front end. i dont understand how should i create the controller in angular and the endpoint in the backend. If anyone can help me i would really appreciate. here are the code snippets in my project. Front End Form – report.component.html <form (ngSubmit)=”savereportdata()” novalidate> <ba-card> <div class=”form-group”> <label for=”middleItemId”>Item ID</label> <input type=”text” class=”form-control” placeholder=”Enter Item ID” [(ngModel)]=”itemId” […]

how can I render an HTML page with express and at the same time pass json data to that HTML?

how can I render an HTML page with express and at the same time pass json data to that HTML? I get the json data from a collection of a mongoDB database. My router file for /solutions looks like this: router.get(‘/’, function (req, res, next) { (err, docs) { res.send(docs); }); }); And in the AngularJS controller: $http.get(‘/solutions’).then(function(res) { console.log(res); }); I don’t specify /solutions in the solutions file because I do that in […]

Can’t sent to mongodb from subpage

Do anyone know why when I tried the code below it only work on the index.html page and not the subpages like registration.component.html? this is my server.js pages // Get dependencies const express = require(‘express’); const path = require(‘path’); const http = require(‘http’); const bodyParser = require(‘body-parser’); const MongoClient = require(‘mongodb’).MongoClient // Get our API routes const api = require(‘./server/routes/api’); const app = express(); // Parsers for POST data app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); // […]

AngularJS Date string vs object error

I’m trying to retrieve a set of user information (by searching firstname) and it returns firstname and booking date (from mongoDB, mongoose schema uses date: Date). Firstname is type=text and booking date is type=date. It returns date as undefined and error message is Error: [ngModel:datefmt] Expected `2017-11-06T16:00:00.000Z to be a date. I read other questions/answers that it’s because type=date expects an object but the JSON is returning a string. I’m really new to Angular JS […]

Next Page »