MongoDB:聚合和$ near

时间:2016-11-23 12:10:27

标签: mongodb mongodb-query spring-data-mongodb

这是我的drivers集合:

{
    "_id" : ObjectId("57e9efd94c02272f4029b5c6"),
    "driverId" : 386,
    "firstname" : "John",
    "middlename" : null,
    "lastname" : "Doe",
    "loc" : {
            "type" : "Point",
            "coordinates" : [
                    36.29102901,
                    -1.29012381
            ]
    },
    "driverState" : "available",
    "contacts" : {
            "email" : "email@email.com",
            "phoneNumber" : "07000000",
            "imei" : "",
            "gcmCode" : ""
    },
    "vehicle" : {
            "vehicleId" : 0,
            "registration" : null,
            "capacity" : 4,
            "vehicleClass" : "GOLD",
            "model" : null,
            "colour" : null
    },
    "cabCompany" : {
            "cabCompanyId" : 8,
            "name" : "princeton cabs"
    }
}

我想将最近的驱动程序提取到按vehicle.vehicleClassvehicle.capacity分组的地理位置。

因此,如果我将GOLD,SILVER作为vehicle.vehicleClass4,7的可能值vehicle.capacity作为GOLD,4的可能值,则查询最多应返回四个文档:

GOLD,7SILVER,4SILVER,7db.drivers.aggregate([ { $match: { loc: { $near: { $geometry: { type: "Point", coordinates: [36.2901920192, -1.29102939202] }, $maxDistance: 100000 } } } }, { $group: { _id: { "vehicle.vehicleClass": "$vehicle.vehicleClass", "vehicle.capacity":"$vehicle.capacity" } } } ]) ,其中每个结果最接近所提供的地理点。

可能如何用mongo

转换为spring-data

这是我尝试的但是我收到了错误:匹配内不允许$ near

Meteor.onConnection(function(conn) {
console.log(conn.clientAddress);
console.log(FlowRouter.getRouteName());
var id = database.insert({
    page: "page",
    ip: conn.clientAddress,
    enterdPagedAt: new Date(), 
    isActive: true
});

0 个答案:

没有答案