2017-04-21 75 views
0

我试图用geoNear和组聚合(其他选项也罚款)做出以下MongoDB的geoNear和组

  1. 收集与loc (2dsphere indexed)user_id领域文件
  2. 有许多是该文件的一个user_id有许多loc

前)

{"user_id":1, "loc": { "type": "Point", "coordinates": ... }} 
{"user_id":1, "loc": { "type": "Point", "coordinates": ... }} 
{"user_id":2, "loc": { "type": "Point", "coordinates": ... }} 
  • 我想使用geoNear与最后插入loc S的每个user_id
  • 我认为它会与聚集组和geoNear的顺序工作,但该文档告诉geoNear必须比其他人先走。

    我该怎么做?

    回答

    0

    援引documentation

    您只能使用$ geoNear作为管道的第一阶段。

    这是聚合管道中$geoNear的当前限制。