Tag: express

MongoDB / ExpressJS – 当ObjectID包含在variables中时,通过_id删除文档

这是我想要做的: app.delete('/:id', function(req, res){ var removal = req.params.id; MongoClient.connect(dbUrl, function(err, db){ var test = db.collection('test'); test.remove({ _id: ObjectId(removal) }); }); }); 但是当我尝试的时候,它会抛出一个错误,因为ObjectId没有被定义。 我在这个问题上遇到了一些麻烦,因为当我在Jade视图中使用item._id时,它只是返回数字,但当然查询集合时不会收回数字。

Express 4应用程序在通过GitHub部署时无法在Azure中运行

我正在使用Visual Studio中的基本Azure Node.js Express 4应用程序模板创build的Express应用程序。 换句话说, 它具有必要的web.config修改来支持Express 4的www\bin结构 。 当通过Visual Studio进行debugging或直接通过Node命令行运行时,此应用可以正常工作。 但是,当我将它连接到GitHub仓库时,从源代码控制部署不起作用。 我可以看到site\wwwroot文件夹中的项目根目录。 更奇怪的是,直接从Visual Studio发布的作品。

平均/ AngularJS应用程序检查对象是否已经发布

我有thig angularJS前端,我在后端使用express,node和mongo。 我的情况如下所示: //my data to push on server $scope.things = [{title:"title", other proprieties}, {title:"title", other proprieties}, {title:"title", other proprieties}] $scope.update = function() { $scope.things.forEach(function(t) { Thing.create({ title: t.title, //other values here }, function() { console.log('Thing added'); }) }) }; //where Thing.create its just an $http.post factory HTML部分看起来像: //html part <button ng-click="update()">Update Thing</button> 然后在同一页上用户有能力改变$scope.things和我的问题是,当我再次调用update()所有的东西都发布两次,因为字面上多数民众赞成我在做什么。 有人可以解释我如何检查'东西'它已经发布到服务器只是为了更新值($ […]

Swift POST请求以错误的格式将body发送到node.js / express应用程序

我想从一个iOS应用程序使用Swift发送JSON对象。 一切正常,但是node.js / express后端的请求体中的主体处于aca-awkward格式,其中在Swift中分析的整个JSON对象是实际的关键字。 那么服务器上收到的是: req.body = { '{"email":"email","password":"password"}': '' } 我希望它是: { "email":"email","password":"password" } 所以我可以通过req.body.email访问键值 我是新来的ios和nodejs之间的http通信,所以也许这是正常的,但它非常恼人。 我的IOS邮政编码是: let url = NSURL(string: "http://localhost:3000/users") let request = NSMutableURLRequest(URL:url!) request.HTTPMethod = "POST" var login_details: [String: AnyObject] = [ "email" : "\(self.email_field.text)", "password" : "\(self.password_field.text)" ] let valid = NSJSONSerialization.isValidJSONObject(login_details) var err: NSError? request.HTTPBody = NSJSONSerialization.dataWithJSONObject(login_details, options: nil, […]

iisnode不会运行Express

我试图运行使用iisnode快递。 我遵循了所提供的示例,但是当尝试使用最新的Express版本和基本示例时,无法使其工作。 我得到的错误Cannot GET /node/parislight/hello.js和其他时间,只是一个The webpage cannot be found 。 我创build了一个hello.js文件(主要快速文件)从快速文档取自。 var express = require('express') var app = express() app.get('/', function (req, res) { res.send('Hello World!') }) var server = app.listen(process.env.PORT, function () { var host = server.address().address var port = server.address().port console.log('Example app listening at http://%s:%s', host, port) }) 我添加了必要的web.config文件(从iisnode中的快速示例中提取) <configuration> <system.webServer> <!– indicates […]

MongoDB(可能的_id数量)

有一个模型 – Post (使用mongoose var Post = new Schema({…}); )。 每次创buildPost模型的新实例时( var post = new Post({…}); post.save(function (error) {…}); ), : _id ( ObjectId("…") )。 我知道这可能是一个愚蠢的问题,但是:尽pipe数据库变得越来越大,是有限的_id还是无限的?

我可以在Azure应用程序服务上运行Node / ExpressJS应用程序,还是必须使用Azure Cloud Service?

我find了在Azure应用程序服务下运行简单的仅限Node的应用程序的例子。 但是对于ExpressJS,我发现的例子都使用了Azure Cloud Service。 新的Azure,只是想弄清楚我应该使用什么。 简单的NodeJS到Azure应用服务https://azure.microsoft.com/zh-cn/documentation/articles/web-sites-nodejs-develop-deploy-mac/ 简单的ExpressJS到Azure云服务https://azure.microsoft.com/zh-cn/documentation/articles/cloud-services-nodejs-develop-deploy-express-app/

更新子文档不工作nodejs mongodb express

我有这个端点: restaRouter.route('/lists/:id/') .post(function(req, res) { db.Restaurant.update({_id: req.params.id}, { $push: { reviews: req.body }}, function(err, doc) { if (err) { res.send(err); } res.json(doc); }) }); 当我做一个职位,它应该find这样的文件使用_id 。 _id是dynamic生成的: { "_id": "571616e420cac41111e90ecf", "title": "Yep", "address": "Somewhere", "about": "Everything", "reviews": [ { "name": "My name", "email": "email@gmail.com", "message": "My message" } ] } 并将项目作为子文档推送到评论字段。 req.body看起来像这样: { "name": "foo", […]

如何在App-Engine上运行的基于快速的Node JS应用程序中获取远程客户端的IP地址

尝试获取IP时,所有标准标题值都包含不正确的值。 req.ip: ::ffff:172.17.0.5 req.headers['x-forwarded-for']: 169.254.160.2 req.socket.remoteAddress: ::ffff:172.17.0.5 所有这些导致错误的IP。

有关如何passport.js工作的问题。 具体关于user.id

我的model , doc或record没有id字段,或者您想要调用它的任何内容。 那么怎么done(null, user.id)作品。 我有一个_id但没有id 。 它看起来像一个护照对象被添加到我的会话与用户在数据库中的_id ,但它是如何得到_id是自动完成的? 在文档中说 在这个例子中,只有用户ID被序列化到会话中 它是如何得到的ID和它是如何得到用户? 我的代码中有类似的例子: passport.serializeUser(function(user, done){ done(null, user.id) }); passport.deserializeUser(function(id, done){ User.findById(id, function(err, user){ done(err, user); }) }); 获取用户ID需要哪些步骤? 我也有 passport.use("login", new LocalStrategy(function(username, password, done){ User.findOne({username : username}, function(err, user){ if(err){return done(err)} if(!user){ return done(null, false, {message : "no User has that name"}) } ……. 我使用passport.use()以某种方式将DB的用户连接到护照方法。 […]