Unable to delete data from mongoDB

You need to pass the _id value as an ObjectID, not a string: var mongodb = require(‘mongodb’); router.delete(‘/contact/:id’, (req, res, next) => { contact.deleteOne({ _id: new mongodb.ObjectID(req.params._id) }, function(err, result) { if (err) { res.json(err); } else { res.json(result); } }); });

Why are functions synchronous in Javascript?

Javascript has asynchronous operations. But, a for loop is synchronous, not asynchronous. The code you show doesn’t use any asynchronous operations, therefore it’s all synchronous. Should myfunc() execute in node and take longer, so that “end” should be invoked earlier because javascript is asynchronous? No. Nothing in myfunc() is asynchronous. That’s all synchronous code in … Read more

Pick data from array of objects and return new object

This really is a simple one liner via map and delete or map and ES6 destructuring as shown in the 2 examples bellow: var data = [{ “first”: “Linda”, “last”: “Donson”, “salary”: “4000USD” }, { “first”: “Mark”, “last”: “Sullivan”, “salary”: “3500USD” } ] console.log(data.map(x => delete(x.salary) && x)) Also if you are concerned about mutating … Read more

im new to making discord bots with node.js, i am having trouble with an error, it says that message is not defined in line 14 and 18

here,try this: client.on(‘message’, message =>{ if(message.content.startsWith(prefix) ||message.author.bot) return; const args = message.content.slice(prefix.lenght).split(/+/); const command = args.shift().toLowerCase(); if(command === ‘blackhumour’){ message.channel.send(‘What is the difference between a kid and a bowling ball? when you put your fingers in one it doesnt scream’); } else if(command === ‘sex’){ message.channel.send(‘no you fucking pervert’); } });