Search Posts

Category: mongoose

Route.delete() requires a callback function but got a [object Undefined]

Keep getting this error but can’t figure out what is wrong with my delete function. “Route.delete() requires a callback function but got a [object Undefined]” const playerController = { index: (request, response) => { Player.find({}) .then(player => response.json(player)) .catch(error => console.log(error)); }, create: (request, response) => { Player.create(request.body) .then(player => response.json(player)) .catch(error => console.log(error)); }, delete: (request, response) => { Player.remove( .then(player => response.json(player)) .catch(error => console.log(error)); //console.log(‘node function’); } }; //- – – – […]

Mongoose query find() returns nothing

I’m querying db with 2 conditions, keyword and user id, both returns correctly in console log but returns nothing, not null, or [], just blank. Something is wrong with the syntax? app.get(“/api/client?”, function (req, res) { console.log(“Search > ” + JSON.stringify(req.query)); //Search > {“keyword”:”emily”,”filterby”:”5a25f3d1d4b3e30792dd53ca”} var keyword = req.query.keyword; var user_id =; Client.find({ $and: [{ “firstname”: new RegExp(‘^’ + keyword + ‘$’, “i”) }, { userid: user_id } ] }, (err, result) => { if […]

How to pass a parameter from angular 2 service to node js function? MEAN

I have a posts collection and each post has an id and userId. I want to find all posts for a specific user (using userId property).. here is my angular2 service: export class PostsService { private _url = ‘/api/posts’; constructor(private _http: Http) { } getPosts(): Observable<Post[]> { return this._http.get(this._url).map(res => res.json()); } getUserPosts(userId: number) { return this._http.get(this._url + ‘/’ + userId).map(posts => posts.json()); } } and my nodejs code : router.get(‘/posts’, function(req, res) { post.find({}).exec(function(err, […]

How can I include data from another collection in my mongoose object?

I am building an app with mongoDB and NodeJS with an Angular front end. I currently have users creating listings and then other users responding with bids within those listings, but want to include data of those responders. I am having a hard time including that user data in the bid create function and not sure why its not pulling. Here is the listing schema var mongoose = require(“mongoose”); var Schema = mongoose.Schema; var Bid […]

Instead of saving inside array, data is getting stored inside new record [duplicate]

This question already has an answer here: Push items into mongo array via mongoose 1 answer I am uploading images using MEAN stack and Multer module. I am able to retrieve images from the angular, and can even post image-paths to Mongoose collection. The problem is I am expecting an array of images but while posting to mongoose, it’s storing each image as a new record. Image schema var imageSchema=new Schema({ productId:{type: String,required: false}, imagePaths: […]

Accesing field outside of callback gives undefined in angular

I have a problem my data structure looks as follows: var mongoose = require(‘mongoose’); var Schema = mongoose.Schema; var schema = new Schema({ name: {type:String, required:true}, domain: {type:String, required:true}, kingdom: {type:String, required:true}, description: {type:String, required:true}, usages:[ {type : mongoose.Schema.ObjectId, ref : ‘Usage’} ], }); module.exports = mongoose.model(‘Flower’,schema,’flowers’); In database usages looks as follows: “usages”: [ { “$oid”: “59785b0c267c14036038324b” } ], after i populate page with data from http get: var app = angular.module(“flowerDataApp”, []); app.controller(‘dataPopulateController’, […]