Skip to main content
added 72 characters in body
Source Link
Sammaye
  • 43.9k
  • 7
  • 110
  • 148

Why are you using hint()? That has got to be some of the most unfuture proof code I have ever seen. If your query does not use the index effectively then you should really change the query or add another index to make the query run over the index. Forcing MongoDB to use an index it cannot find itself might actually slow your query further because it will attempt to use a b-tree that does not provide a shortcut.

Infact your query:

db.tablebusiness.find({ "LongitudeLatitude" : { "$nearSphere" : [106.772835, -6.186753], "$maxDistance" : 0.044983732050783008 }, "Prominent" : { "$gte" : 15 }, "indexContents" : { "$all" : [/^warung/] } })

Will use the index you created without using hint(). If you make a better index one day more effective for this query then using hint() will stop this query from being faster due to that new index. Not only that but you will have to change index names in all of your code.

As for changing the name of the index: I think you have to drop it first and then reindex creating a new index of your own name (though as @Thilo mentions, self named indexes are going to be removed).

Why are using hint()? That has got to be some of the most unfuture proof code I have ever seen. If your query does not use the index effectively then you should really change the query or add another index to make the query run over the index. Forcing MongoDB to use an index it cannot find itself might actually slow your query further because it will attempt to use a b-tree that does not provide a shortcut.

Infact your query:

db.tablebusiness.find({ "LongitudeLatitude" : { "$nearSphere" : [106.772835, -6.186753], "$maxDistance" : 0.044983732050783008 }, "Prominent" : { "$gte" : 15 }, "indexContents" : { "$all" : [/^warung/] } })

Will use the index you created without using hint(). If you make a better index one day more effective for this query then using hint() will stop this query from being faster due to that new index. Not only that but you will have to change index names in all of your code.

As for changing the name of the index: I think you have to drop it first and then reindex creating a new index of your own name.

Why are you using hint()? That has got to be some of the most unfuture proof code I have ever seen. If your query does not use the index effectively then you should really change the query or add another index to make the query run over the index. Forcing MongoDB to use an index it cannot find itself might actually slow your query further because it will attempt to use a b-tree that does not provide a shortcut.

Infact your query:

db.tablebusiness.find({ "LongitudeLatitude" : { "$nearSphere" : [106.772835, -6.186753], "$maxDistance" : 0.044983732050783008 }, "Prominent" : { "$gte" : 15 }, "indexContents" : { "$all" : [/^warung/] } })

Will use the index you created without using hint(). If you make a better index one day more effective for this query then using hint() will stop this query from being faster due to that new index. Not only that but you will have to change index names in all of your code.

As for changing the name of the index: I think you have to drop it first and then reindex creating a new index of your own name (though as @Thilo mentions, self named indexes are going to be removed).

Source Link
Sammaye
  • 43.9k
  • 7
  • 110
  • 148

Why are using hint()? That has got to be some of the most unfuture proof code I have ever seen. If your query does not use the index effectively then you should really change the query or add another index to make the query run over the index. Forcing MongoDB to use an index it cannot find itself might actually slow your query further because it will attempt to use a b-tree that does not provide a shortcut.

Infact your query:

db.tablebusiness.find({ "LongitudeLatitude" : { "$nearSphere" : [106.772835, -6.186753], "$maxDistance" : 0.044983732050783008 }, "Prominent" : { "$gte" : 15 }, "indexContents" : { "$all" : [/^warung/] } })

Will use the index you created without using hint(). If you make a better index one day more effective for this query then using hint() will stop this query from being faster due to that new index. Not only that but you will have to change index names in all of your code.

As for changing the name of the index: I think you have to drop it first and then reindex creating a new index of your own name.