我正在开发一个与Etherpad有关的项目,我想到了使用Meteor.js(我认为它非常适合这种项目).如果我想让它可扩展,那么操作转换对我的项目非常重要.我目前的知识表明流星不支持开箱即用的操作转换(如果我错了,请纠正我).所以基本上我的问题是如何在meteor.js中实现操作转换?
我尝试使用Neil Fraser的这个库google-diff-match-patch,但在应用补丁时遇到了问题(虽然它很容易在meteor.js之外工作).
那有什么建议吗?
MongoDb的$ project聚合运算符是否可以将文档重组为数组?
这是我到目前为止所做的:
var pipeline = [];
var project = {
$project : {
x: "$_id",
y: "$y" ,
_id : 0
}
};
pipeline.push(project);
model.aggregate( pipeline, callback);
Run Code Online (Sandbox Code Playgroud)
这给了我输出的形式:
[
{
x: '...',
y: '...'
}
....
]
Run Code Online (Sandbox Code Playgroud)
我想拥有:
[
['..','..']
....
]
Run Code Online (Sandbox Code Playgroud)
我可以通过迭代来轻松地重构输出,但是真的很想知道聚合本身是否可以返回数组而不是对象.
我试图通过elasticsearch聚合动态字段(不同文档不同).文件如下:
[{
"name": "galaxy note",
"price": 123,
"attributes": {
"type": "phone",
"weight": "140gm"
}
},{
"name": "shirt",
"price": 123,
"attributes": {
"type": "clothing",
"size": "m"
}
}]
Run Code Online (Sandbox Code Playgroud)
如您所见,文档中的属性发生了变化.我想要实现的是聚合这些属性的字段,如下所示:
{
aggregations: {
types: {
buckets: [{key: 'phone', count: 123}, {key: 'clothing', count: 12}]
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用elasticsearch的聚合功能来实现这一目标,但却无法找到正确的方法.是否有可能通过聚合实现?或者我应该开始寻找方面,认为它似乎被剥夺了.
我正在尝试使用mongoDb的$ geoNear聚合运算符通过以下方式计算用户到当前位置的距离:
'$geoNear': {
near: currentLocation,
distanceField: 'distance',
spherical: true,
}
Run Code Online (Sandbox Code Playgroud)
与currentLocation类似:
{ "type" : "Point", "coordinates" : [ -122.1575745, 37.4457966 ] }
Run Code Online (Sandbox Code Playgroud)
我的收藏品属于以下类型(使用猫鼬):
users = [{
....
location : { // GeoJSON Point or I think it is ;)
type: {
type: String
},
coordinates: []
}
....
}]
Run Code Online (Sandbox Code Playgroud)
我正在使用索引(还是猫鼬的语法):
userSchema.index({
location: '2dsphere'
});
Run Code Online (Sandbox Code Playgroud)
现在我面临的问题是,如果我使用上述提到的currentLocation(以GeoJSON的形式)进行查询,我会得到怪异的距离(非常大的数字),但是如果我使用currentLocation.coordinates,即使用旧式坐标对([-122.1575745 ,37.4457966]),我得到正确的结果。但是geoNear的mongoDb文档明确表示,我们可以使用GeoJSON点或旧式坐标对进行查询。
我很好奇,想知道GeoJSON点对和传统坐标对之间到底有什么区别?
例如:
{ "_id" : ObjectId("5277679914c6d8f00b000003"), "location" : { "type" : "Point", "coordinates" : [ 106.6202887, -6.1293536 ] } …Run Code Online (Sandbox Code Playgroud) mongodb geojson node.js aggregation-framework mongodb-indexes