Search Posts

Category: mongoose

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’, […]