Skip to main content

Posts

Showing posts with the label Mongoose

Why do we need to add .end() to a response?

Currently building a RESTful API with express on my web server, and some routes like the delete route for a document with mongoose ex. await Note.findByIdAndRemove(request.params.id) response.status(204).end() send response statuses with end() Why do I need to add the .end() ? What in these cases, and why cant one just send response.status(204) With some responses that return json, the response.status(201).json works fine by Oscar in StackOverflow on July 03, 2022 . Answer Only certain methods with Express or the http interface will send the response. Some methods such as .status() or .append() or .cookie() only set state on the outgoing response that will be used when the response is actually sent - they don't actually send the response itself. So, when using those methods, you have to follow them with some method that actually sends the response such as .end() . In your specific example of: response.status(204) You c...

Is there a way to get only User item from a collection using Mongoose DB?

So this is my Schema folder: module.exports = mongoose.model( 'premium', new mongoose.Schema({ User: String, Name: String, Expire: Number, Permanent: Boolean, }) ); So I want to get from database only User and Name items and use it in embed on discord.js, but I am not finding any way to do so by Christy in StackOverflow on June 05, 2022 . Answer You can use select and specify field you want with 1 and not with 0 : dbSchemas.SomeValue.find({}).select({ "User": 1, "Name": 1}); by arnaud_h on June 05, 2022 .