MongoDB java driver を
index 作成で
com.mongodb.MongoCommandException: Command failed with error 67: 'Values in v:2 index key pattern cannot be of type bool. Only numbers > 0, numbers < 0, and strings are allowed.' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "Values in v:2 index key pattern cannot be of type bool. Only numbers > 0, numbers < 0, and strings are allowed.", "code" : 67, "codeName" : "CannotCreateIndex" } at com.mongodb.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:115) at com.mongodb.connection.CommandProtocol.execute(CommandProtocol.java:114) at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:159) at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:286) at com.mongodb.connection.DefaultServerConnection.command(DefaultServerConnection.java:173) at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:215) at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:198) at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:170) at com.mongodb.operation.CreateIndexesOperation$1.call(CreateIndexesOperation.java:116) at com.mongodb.operation.CreateIndexesOperation$1.call(CreateIndexesOperation.java:111) at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:230) at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:221)
Values in v:2 index key pattern cannot be of type bool.
なので、
boolean 値は
実装上以下のように
collection.createIndex(new BasicDBObject().append("mbid", 1).append("unique", true));
mongo-java-driver/DBCollection.java at 2.x · mongodb/mongo-java-driver
の
/** * Forces creation of an index on a set of fields with the default options, if one does not already exist. * * @param keys a document that contains pairs with the name of the field or fields to index and order of the index * @throws MongoException * @mongodb.driver.manual /administration/indexes-creation/ Index Creation Tutorials */ public void createIndex( final DBObject keys ){ createIndex( keys , defaultOptions( keys ) ); }
そもそも、
以前の
version 3 からは
以下の
collection.createIndex(new BasicDBObject().append("mbid", 1), new IndexOptions().unique(true));
サーバー再起動して、
結構長いこと
以上です。
コメント