MongoDB select where in array of _id?
Easy 🙂 db.collection.find( { _id : { $in : [1,2,3,4] } } ); taken from: https://www.mongodb.com/docs/manual/reference/operator/query/in/#mongodb-query-op.-in
Easy 🙂 db.collection.find( { _id : { $in : [1,2,3,4] } } ); taken from: https://www.mongodb.com/docs/manual/reference/operator/query/in/#mongodb-query-op.-in
You can also set the path that static files will be served to the web from by specifying an additional (first) parameter to use() like so: app.use(“/public”, express.static(__dirname + “/public”)); app.use(“/public2”, express.static(__dirname + “/public2”)); That way you get two different directories on the web that mirror your local directories, not one url path that fails … Read more
You can add a text index to your Mongoose schema definition that lets you use the $text operator in your find queries to search all fields included in the text index. To create an index to support text search on, say, name and profile.something: var schema = new Schema({ name: String, email: String, profile: { … Read more
Use req.app, req.app.get(‘somekey’) The application variable created by calling express() is set on the request and response objects. See: https://github.com/visionmedia/express/blob/76147c78a15904d4e4e469095a29d1bec9775ab6/lib/express.js#L34-L35
In your ensureAuthenticated method save the return url in the session like this: … req.session.returnTo = req.originalUrl; res.redirect(‘/login’); … Then you can update your passport.authenticate route to something like: app.get(‘/auth/google/return’, passport.authenticate(‘google’), function(req, res) { res.redirect(req.session.returnTo || “https://stackoverflow.com/”); delete req.session.returnTo; });
None of the existing answers accomplish what the OP originally asked for, which is to override the default Reason-Phrase (the text appearing immediately after the status code) sent by Express. What you want is res.statusMessage. This is not part of Express, it’s a property of the underlying http.Response object in Node.js 0.11+. You can use … Read more
Easiest solution: app.disable(‘etag’); Alternate solution here if you want more control: http://vlasenko.org/2011/10/12/expressconnect-static-set-last-modified-to-now-to-avoid-304-not-modified/
req.query will return a JS object after the query string is parsed. /user?name=tom&age=55 – req.query would yield {name:”tom”, age: “55”} req.params will return parameters in the matched route. If your route is /user/:id and you make a request to /user/5 – req.params would yield {id: “5”} req.param is a function that peels parameters out of … Read more
app.listen() returns http.Server. You should invoke close() on that instance and not on app instance. Ex. app.get( ‘/auth/github/callback’, passport.authenticate(‘github’, { failureRedirect: ‘/login’ }), function(req, res) { res.redirect(“https://stackoverflow.com/”); setTimeout(function () { server.close(); // ^^^^^^^^^^^ }, 3000) } ); var server = app.listen(‘http://localhost:5000/’); // ^^^^^^^^^^ You can inspect sources: /node_modules/express/lib/application.js
To get a file’s size in megabytes: var fs = require(“fs”); // Load the filesystem module var stats = fs.statSync(“myfile.txt”) var fileSizeInBytes = stats.size; // Convert the file size to megabytes (optional) var fileSizeInMegabytes = fileSizeInBytes / (1024*1024); or in bytes: function getFilesizeInBytes(filename) { var stats = fs.statSync(filename); var fileSizeInBytes = stats.size; return fileSizeInBytes; }