티스토리 뷰
Database/mongoDB
[mongoDB/Error] There is more than one 2dsphere index; unsure which to use for $geoNear
angieveloper 2022. 3. 27. 00:09🚨 에러 상황
Node.js로 Mongoose의 aggregate로 $geoNear 를 사용했더니 아래와 같은 에러 발생
"There is more than one 2dsphere index; unsure which to use for $geoNear
✨ 해결 방법
1. 만약 하나의 2dsphere index만 필요하다면 불필요한 index 삭제
아래 링크를 참고해서 삭제한다.
https://shunnyjang.tistory.com/14?category=1048808
[mongoDB] collection의 index 관리
⛳️ 1. index 조회 locations라는 collection에 생성한 index들을 조회하고 싶을 때 .getIndexes() > db.locations.getIndexes() 아래처럼 index 종류가 출력된다. [ { v: 2, key: { _id: 1 }, name: '_id_' }, {..
shunnyjang.tistory.com
2. 어떤 key에 대해서 하는지 명시
{
$geoNear: {
near: { type: "Point", coordinates: [ -73.98142 , 40.71782 ] },
key: "location",
distanceField: "dist.calculated",
query: { "category": "Parks" }
}
$geoNear 내에 key 값을 추가해서 명시한다.
'Database > mongoDB' 카테고리의 다른 글
[mongoDB] collection의 index 관리 (0) | 2022.03.26 |
---|---|
[mongoDB/linux] mongo db 설치 (0) | 2022.03.14 |
댓글