Closed deepakmalikk closed 4 years ago
const express =require('express') const mongo = require('mongoose') const router =express.Router() const Ninja=require('../models/ninja') mongo.set('useCreateIndex',true) //get a list of ninjas from db router.get('/ninjas',function(req,res,next){
Ninja.aggregate([{
$geoNear:{
near: {type:'point',coordinates:[parseFloat(req.query.lng),parseFloat(req.query.lat)]}, spherical: true ,maxdistance :100000,distanceField: "dist.calulated"} }]).then(function(ninjas){ res.send(ninjas) }) })
//add a new of ninjas from db router.post('/ninjas',function(req,res,next){
Ninja.create(req.body).then((ninja) => { res.send(ninja) }).catch(next)
})
// update a new of ninjas from db router.put('/ninjas/:id',function(req,res,next){ Ninja.findByIdAndUpdate({_id: req.params.id},req.body).then(function() { Ninja.findOne({_id: req.params.id},req.body).then(function(ninja){
res.send(ninja)
})
})
})
//Delete a ninjas from db router.delete('/ninjas/:id',function(req,res,next){
Ninja.findByIdAndRemove({_id: req.params.id}).then(function(ninja){
res.send(ninja)
})
})
module.exports=router
instead of type "module.export = NameOfModel" type this : module.exports = name of model
and it will work because that code gotta be 'exports' but not 'export' I'd the same issue
Ninja.create is not working showing an error that ninja.create is not a function