Mongoose版本:3.6节点版本:0.10
我一直试图解决这个问题几个小时.我想找到比maxDistance更接近某些坐标的所有文档.我正在尝试使用MongoDB(2dsphere)的GeoJSON规范,这样我就可以以米为单位输入距离.
这是我的架构"venue.js":
var db = require('mongoose'),
Schema = db.Schema,
ObjectId = Schema.ObjectId;
var venueSchema = new Schema({
geo: { type: [Number], index: '2dsphere'},
city: String,
name: String,
address: String
});
module.exports = db.model('Venue', venueSchema);
Run Code Online (Sandbox Code Playgroud)
这是我插入查询ctrlVenue.js的地方:
var Venue = require('../models/venue.js');
VenueController = function(){};
/** GET venues list ordered by the distance from a "geo" parameter. Endpoint: /venues
Params:
- geo: center for the list of venues - longitude, latitude (default: 25.466667,65.016667 - Oulu);
- maxDistance: maxímum distance from the center …Run Code Online (Sandbox Code Playgroud) 我正在研究MEAN-STACK应用程序.使用Mean-cli packgae of node.其中我使用的是darksky weather API,在包名称信息中.我在平均应用程序的自定义文件夹中有4个其他包.我是如何启用CORS以便所有API请求都不会失败并返回响应的.
我用谷歌搜索,发现我必须添加这个中间件.
//CORS middleware
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', 'example.com');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
}
Run Code Online (Sandbox Code Playgroud)
我应该在哪里添加这个.在我们使用跨源请求的每个包中或在某个全局文件中.
我试过在服务器-route文件中添加这个中间件?信息包和confile的express.js文件但它没有用.
我目前正在使用Heroku的评论应用程序功能,这很棒.唯一的问题是,目前,当从拉取请求创建新应用程序时,它只有1个Web Dyno和0个工作者.我的应用程序需要几个Web Dynos和worker,因此我需要在我的仪表板中手动编辑它们.有没有办法(例如通过app.json配置)指定创建新的评论应用程序时使用的Dynos数量及其类型?
我正在运行Mocha测试(将Chai作为断言库).
目前,JSHint每次遇到类似这样的行时都会发出警告:
期望(ERR).to.be.null;
报告的问题是:
期望一个标识符,而是看到'null'(保留字).
JSHint是否有任何放松选项来解决此问题?目前我唯一找到的解决方案是在文件开头包含特殊选项:
/*jshint -W024*/
问题在于它需要包含在每个测试文件中(我宁愿将JSHint选项与代码本身分开).我似乎没有在选项列表中找到太多.
所以我试图在一个名为login_routes.js的独立JS文件中分离我的登录路由
我一直收到这个特定的错误:
TypeError:Router.use()需要中间件函数,但在Function处有一个Object.(/Users/ethanthomas/Desktop/mean-stuff/express-server/node_modules/express/lib/router/index.js:446:13)
不完全理解它要求我做implement什么?
login_routes.js:
var express = require('express');
var app = express();
app.route('/login')
.get(function(req, res, next) {
res.send('this is the login form');
})
.post(function(req, res, next) {
console.log('processing');
res.send('proccessing the login form!');
});
Run Code Online (Sandbox Code Playgroud)
server.js:
var express = require('express');
var app = express();
var path = require('path');
var adminRoutes = require('./app/routes/admin_routes');
var loginRoutes = require('./app/routes/login_routes');
app.use('/admin', adminRoutes);
app.use('/login', loginRoutes);
//send our index.html file to the user for the home page
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/index.html'));
}); …Run Code Online (Sandbox Code Playgroud)