[JAVA-1261] ensureIndex is running fine but createIndex is throwing error. Created: 03/Jun/14 Updated: 13/Apr/16 Resolved: 13/Apr/16 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Authentication |
| Affects Version/s: | 2.10.1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Rajesh Sharma | Assignee: | Ross Lawley |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Client on Windows and Server on Linux, Database is 2.4.8. |
||
| Attachments: |
|
| Description |
|
When i run use DBCollection.ensureIndex() option it is creating Index without any issue but this method is depreciated and it is suggested to use createIndex method. Using createIndex is throwing the following Exception. I am trying to create TTL Collection using following DBObjects.
|
| Comments |
| Comment by Rajesh Sharma [ 04/Jun/14 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks a lot for your prompt reply. Have a great day! | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ross Lawley [ 04/Jun/14 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Fixed in future versions of the driver | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ross Lawley [ 04/Jun/14 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
No problems, I believe the error is caused by the missing namespace in the index options and isn't being reported back correctly. Changing the options in the testcase to:
Fixes the issue. In later versions of the driver the namespace is automatically added for you. The namespace should have the key "ns" and the value of: "<database_name>.<collection_name>" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Rajesh Sharma [ 04/Jun/14 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
With 2.12.2 it's working fine. Behavior of createIndex is good but we are using version 2.10.1 for this project as we have other dependencies and we don't want to have any conflict. May be we will use ensureIndex and not createIndex with version 2.10.1 as createIndex is buggy in that version. Thanks a lot!. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ross Lawley [ 04/Jun/14 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
rajeshks117 are you able to test against a newer version of the Java driver? 2.10.1 was released in December 2013 and the latest is now 2.12.2. There have been numerous bug fixes since then https://github.com/mongodb/mongo-java-driver/releases | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Rajesh Sharma [ 04/Jun/14 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
This is the test java file. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Rajesh Sharma [ 04/Jun/14 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Yes the mongo Java Driver is Version 2.10.1. Authentication was enables and i was able to authenticate myself. Here is Simple source code to replicate this. I saw a weired behaviour. createIndex will either fail with authentication issue or not create Index. ensureIndex will always succeed. Here is test case. Also attached the file as it's showing wrong format in preview
Here is the output of system.users collection.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ross Lawley [ 04/Jun/14 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi rajeshks117 Thanks for the ticket, I need some more information to help me understand what is happening here as ensureIndex stores a cache of created indexes and if the index isn't in the cache then it calls createIndex itself. Can you confirm the Java driver version you are using? 2.10.1 is marked above but ensureIndex wasn't deprecated until 2.12.0. Can you confirm you running with authentication and have you authenticated? Finally, could you provide a test case reproducing the error? |