2

My query does not find documents in my MongoDB collection

This is example object in the database (notice that position.x and position.y are Longs in Salat)

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

This is my query

{
  "worldSlug": "test",
  "position": {
    "x": {
     "$gt": -31,
     "$lt": 29
    },
    "y": {
      "$gt": -27,
      "$lt": 33
    }
  }
}
Community
  • 1
  • 1
Mateusz
  • 498
  • 4
  • 17

1 Answers1

3

You need to use dot notation to query on embedded fields. Use a query object like this instead:

{
  "worldSlug": "test",
  "position.x": {
     "$gt": -31,
     "$lt": 29
  },
  "position.y": {
      "$gt": -27,
      "$lt": 33
  }
}
Mateusz
  • 498
  • 4
  • 17
JohnnyHK
  • 305,182
  • 66
  • 621
  • 471
  • Nearly ok. The solution was that dot notation. `floatApprox` property was shown only in shell because it does not support Long type – Mateusz Jan 05 '13 at 17:50