2

クエリで MongoDB コレクション内のドキュメントが見つからない

これはデータベース内のオブジェクトの例です (position.x と position.y は Salat の Long であることに注意してください)。

{
  "_id": ObjectId("50e85039e4b0f225b98b8b34"),
  "worldSlug": "test",
  "position": {
    "x": {
      "floatApprox": 3
    },
    "y": {
      "floatApprox": 3
    }
  },
  "type": "village",
  "owner": "mati",
  "health": {
    "got": 500,
    "total": 500
  }
}

これは私のクエリです

{
  "worldSlug": "test",
  "position": {
    "x": {
     "$gt": -31,
     "$lt": 29
    },
    "y": {
      "$gt": -27,
      "$lt": 33
    }
  }
}
4

1 に答える 1

3

埋め込みフィールドを照会するには、ドット表記を使用する必要があります。代わりに、次のようなクエリ オブジェクトを使用します。

{
  "worldSlug": "test",
  "position.x": {
     "$gt": -31,
     "$lt": 29
  },
  "position.y": {
      "$gt": -27,
      "$lt": 33
  }
}
于 2013-01-05T17:41:09.550 に答える