I have a collection that looks like this:
Mongodb Collection Data:
/* 1 */
{
"_id" : "X1255",
"member" : {
"id" : "X1255",
"address" : [
{
"place" : "TEST1",
"location" : {
"type" : "Point",
"coordinates" : [
-83.66403,
31.02459
]
}
},
{
"place" : "TEST2",
"location" : {
"type" : "Point",
"coordinates" : [
-83.61883,
31.54664
]
}
}
]
}
}
/* 2 */
{
"_id" : "X30127",
"member" : {
"id" : "X30127",
"address" : [
{
"place" : "TEST3",
"location" : {
"type" : "Point",
"coordinates" : [
-83.61883,
31.54664
]
}
}
]
}
}
There is a 2dsphere index on member.address.location.coordinates.
Mongod geonear query's optional params return only one coorninates value. Even thoung collections 1st and 2nd record has same coordinates value, the query is returning only one sub document. But expected result is query should give all sub documents when it has multiple matching coordinates in the collection data.
Mongodb Query:
db.getCollection('test').aggregate([
{"$geoNear":{"near":{"type":"Point","coordinates":[-83.672608,32.0390586]},
"maxDistance":160934,"distanceField":"dist.distance",
"includeLocs":"dist.locs","spherical":true}},
{"$unwind":"$member.address"},
{"$project":{"member":{"$cond":[{"$and":[
{"$eq":["$member.address.location.coordinates","$dist.locs.coordinates"]}]},
"$member",[]]}}}
])
Actual result:
/* 1 */
{
"_id" : "X1255",
"member" : {
"id" : "X1255",
"address" : [
{
"place" : "TEST1",
"location" : {
"type" : "Point",
"coordinates" : [
-83.66403,
32.02459
]
}
}
]
}
}
/* 2 */
{
"_id" : "X30127",
"member" : {
"id" : "X30127",
"address" : [
{
"place" : "TEST3",
"location" : {
"type" : "Point",
"coordinates" : [
-83.61883,
31.54664
]
}
}
]
}
}
Expected result:
/* 1 */
{
"_id" : "X1255",
"member" : {
"id" : "X1255",
"address" : [
{
"place" : "TEST1",
"location" : {
"type" : "Point",
"coordinates" : [
-83.66403,
32.02459
]
}
}
]
}
}
/* 2 */
{
"_id" : "X1255",
"member" : {
"id" : "X1255",
"address" : [
{
"place" : "TEST2",
"location" : {
"type" : "Point",
"coordinates" : [
-83.61883,
31.54664
]
}
}
]
}
}
/* 3 */
{
"_id" : "X30127",
"member" : {
"id" : "X30127",
"address" : [
{
"place" : "TEST3",
"location" : {
"type" : "Point",
"coordinates" : [
-83.61883,
31.54664
]
}
}
]
}
}