[JAVA-790] Wrong type for option 'unique' in GridFS constructor Created: 22/Mar/13  Updated: 31/Mar/15  Resolved: 22/Aug/13

Status: Closed
Project: Java Driver
Component/s: GridFS
Affects Version/s: 2.10.1
Fix Version/s: 2.11.3, 3.0.0

Type: Bug Priority: Major - P3
Reporter: Rainer Reich Assignee: Jeffrey Yemin
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

using mongodb-linux-x86_64-2.4.0


Issue Links:
Related
related to JAVA-401 "not master" MongoException when usin... Closed

 Description   

In the ctor of GridFS the following call on DBCollection#ensureIndex sets a wrong value respectively the wrong type for option "unique", so that the index will not be found even if it exists:

_chunkCollection.ensureIndex( BasicDBObjectBuilder.start().add( "files_id" , 1 ).add( "n" , 1 ).get() , BasicDBObjectBuilder.start().add( "unique" , 1 ).get() );

The correct value would be true instead of 1:

_chunkCollection.ensureIndex( BasicDBObjectBuilder.start().add( "files_id" , 1 ).add( "n" , 1 ).get() , BasicDBObjectBuilder.start().add( "unique" , true ).get() );



 Comments   
Comment by Jeffrey Yemin [ 31/Mar/15 ]

Closing all resolved 3.0.0 issues, as 3.0.0 has been tagged and released.

Comment by auto [ 12/Sep/13 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-790: Change index options from

{unique: 1}

to

{unique : true}

Branch: 2.11.x
https://github.com/mongodb/mongo-java-driver/commit/9bb29e72afddc3639a5ff71c385f4142af8fcd39

Comment by auto [ 22/Aug/13 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-790: Change index options from

{unique: 1}

to

{unique : true}

Branch: master
https://github.com/mongodb/mongo-java-driver/commit/5e98c07285817fcb4cc7ae76ddecc89857c0c6f9

Comment by auto [ 17/Aug/13 ]

Author:

{u'username': u'trnl', u'name': u'Uladzimir Mihura', u'email': u'trnl.me@gmail.com'}

Message: fix(driver-compat) JAVA-790: wrap ensureIndex calls in GridFS into try-catch
Branch: 3.0.x
https://github.com/mongodb/mongo-java-driver/commit/7de8c810afed408bd6f9f42cc5adafef4e161140

Comment by Uladzimir Mihura [ 17/Aug/13 ]

So ok, it fixes a problem already.

I'll update 3.x code.

-vova

Comment by Jeffrey Yemin [ 17/Aug/13 ]

In 2.11.2, the ensureIndex calls were put in a try-catch. See JAVA-401.

Comment by Sébastien Vauclair [ 10/Apr/13 ]

We encountered the same problem, for a slightly different reason: some of our servers are configured to access Mongo using a readonly user, which is therefore not allowed to create any index.

We will use the same temporary workaround DB#setReadOnly() until a fix is released.

Comment by Jeffrey Yemin [ 22/Mar/13 ]

OK, I see. I can fix this in master and push a snapshot release to sonatype, but we don't have plans yet for another release (unless a major bug is found in 2.11.0). Would you use a snapshot release?

Comment by Rainer Reich [ 22/Mar/13 ]

I don't know if it's a performance issue. We have a pretty special setup, where we connect to a single Mongo node, not to a replica set. The problem is, that Mongo then tries to create an index and complains that it's not connected to the primary. Our temporary workaround is to use DB#setReadOnly() which prevents DBCollection#ensureIndex() from doing anything.

Comment by Jeffrey Yemin [ 22/Mar/13 ]

Are you noticing any performance degradation as a result of this? Note that the server will still ignore the index creation once it's been created the first time.

Comment by Rainer Reich [ 22/Mar/13 ]

Well, ensureIndex ends up calling DBApiLayer#createIndex(...). There idxs.findOne(full) returns null, because it does not find any document where key unique has the value 1, because the value is really true.
You can reproduce this in the mongo shell:
'db.system.indexes.find(

{"unique":1}

)' won't return anything, but
'db.system.indexes.find(

{"unique":true}

)' will return the index

Comment by Jeffrey Yemin [ 22/Mar/13 ]

I'm not sure what you mean. Why won't it be found?

Generated at Thu Feb 08 08:53:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.