1

I've configured my environment and I've downloading Solr 4.7 The idea is make an indexing my mongodb database. For this I've installed the mongo-connector like appear here: https://github.com/10gen-labs/mongo-connector

running this commands:

git clone https://github.com/10gen-labs/mongo-connector.git
cd mongo-connector
python setup.py install

I've set the replica mongod --replSet myDevReplSet

And I've modified my schema.xml adding this lines:

 <fields>
   <field name="_id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> 
   <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> 
   <field name="sex" type="string" indexed="true" stored="true" required="true" multiValued="false" />
   <field name="email" type="string" indexed="true" stored="true" required="true" multiValued="false" />
   <field name="phone" type="string" indexed="true" stored="true" required="true" multiValued="false" />
 </fields>
 <uniqueKey>_id</uniqueKey> 

Modified too my solr-config.xml adding this three lines:

  <lib dir="../../../contrib/dataimporthandler/lib/" regex=".*\.jar" />
  <lib dir="../../../dist/" regex="solr-dataimporthandler-\d.*\.jar" />
  <lib dir="../../../dist/mongo-java-driver-2.11.4.jar" />

Then my data-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
<dataSource name="mongod" type="JdbcDataSource" 
              driver="com.mongodb.jdbc.MongoDriver" 
              url="mongodb://localhost:27017/db1"/>
    <document>
    <entity name="usuario" dataSource="mongod" query="select * from user">
        <field column="_id" name="_id"/>
    <field column="sex" name="sex"/> 
    <field column="email" name="email"/> 
    <field column="phone" name="phone"/> 
        <!-- other fileds -->
    </entity>
    </document> 
</dataConfig>

But when I try use the /dataimport to index my database I've this error:

Full Import failed:java.lang.RuntimeException: java.lang.RuntimeException: org.apache.solr.handler.dataimport.DataImportHandlerException: Could not load driver: com.mongodb.jdbc.MongoDriver Processing Document # 1
    at org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java:276)
    at org.apache.solr.handler.dataimport.DataImporter.doFullImport(DataImporter.java:411)
    at org.apache.solr.handler.dataimport.DataImporter.runCmd(DataImporter.java:483)
    at org.apache.solr.handler.dataimport.DataImporter$1.run(DataImporter.java:464)
Caused by: java.lang.RuntimeException: org.apache.solr.handler.dataimport.DataImportHandlerException: Could not load driver: com.mongodb.jdbc.MongoDriver Processing Document # 1
    at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:416)
    at org.apache.solr.handler.dataimport.DocBuilder.doFullDump(DocBuilder.java:329)
    at org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java:237)
    ... 3 more
Caused by: org.apache.solr.handler.dataimport.DataImportHandlerException: Could not load driver: com.mongodb.jdbc.MongoDriver Processing Document # 1
    at org.apache.solr.handler.dataimport.DataImportHandlerException.wrapAndThrow(DataImportHandlerException.java:71)
    at org.apache.solr.handler.dataimport.JdbcDataSource.createConnectionFactory(JdbcDataSource.java:116)
    at org.apache.solr.handler.dataimport.JdbcDataSource.init(JdbcDataSource.java:64)
    at org.apache.solr.handler.dataimport.DataImporter.getDataSourceInstance(DataImporter.java:383)
    at org.apache.solr.handler.dataimport.ContextImpl.getDataSource(ContextImpl.java:99)
    at org.apache.solr.handler.dataimport.SqlEntityProcessor.init(SqlEntityProcessor.java:53)
    at org.apache.solr.handler.dataimport.EntityProcessorWrapper.init(EntityProcessorWrapper.java:74)
    at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:433)
    at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:414)

I put the mongo-java-driver-2.11.4 in this path but the error is still there:

example/solr/lib/mongo-java-driver-2.11.4.jar

Please can you help me to index my database?? NOTE: Im not able to create solr tag in this stackexchange

  • The java driver for MongoDB is not a JDBC driver, so at the very least your driver definition is incorrect – Adam C Apr 7 '14 at 15:37
  • where can I find the correct driver?? – HCarrasko Apr 7 '14 at 15:38
  • There is no (non-experimental) JDBC driver as far as I know - MongoDB is not a SQL database, hence the query you have listed is also incorrect. Looking at the docs, the mongo connector replicates all data from the database anyway, so the query is not needed - I think you have a something fundamentally incorrect here, but I am not familiar enough with SOLR or the connector to tell you exactly what. – Adam C Apr 7 '14 at 16:36
1

You can use SolrMongoImporter


Example of usage:

<lib path="../../dist/solr-mongo-importer.jar" />
<lib path="../../dist/mongo.jar" />


<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
    <dataSource name="MyMongo" type="MongoDataSource" database="Inventory" />
    <document name="Products">
        <entity processor="MongoEntityProcessor"
             query="{'Active':1}"
             collection="ProductData"
             datasource="MyMongo"
             transformer="MongoMapperTransformer" >

            <field column="title"           name="title"       mongoField="Title"/>
            <field column="description"     name="description" mongoField="Long Description"/>
            <field column="brand"           name="brand"  />
        </entity>
    </document>
</dataConfig>
  • Why do you need Solr over MongoDB? Can't MongoDB do the needful for any indexing and searching... – HaBo Apr 25 '16 at 5:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.