2014-09-12 129 views
0

從統一JDBC download page如何使用Unity JDBC驅動程序連接兩個MongoDB集合?

如果SQL查詢需要加入或不MongoDB的支持的功能,那麼查詢被提升到UnityJDBC(試用版)。 UnityJDBC試用版沒有失效日期,並且功能完全正常,但僅限於返回100個結果。

然而,當我嘗試加入使用任何語法兩個表像

SELECT * from a, b WHERE a.id = b.id 
SELECT * from a INNER JOIN b ON a.id = b.id 
SELECT * from a INNER JOIN b USING (id) 

結果如下:

Exception: java.sql.SQLException: ERROR: No schema defined. The default schema location is _schema in the current database. You need write permission to create this collection. Otherwise, use the schema parameter to set a file location (e.g. schema=mongo.xml) to store the schema. See connection parameters at http://www.unityjdbc.com/mongojdbc/ for more details. 
java.sql.SQLException: ERROR: No schema defined. The default schema location is _schema in the current database. You need write permission to create this collection. Otherwise, use the schema parameter to set a file location (e.g. schema=mongo.xml) to store the schema. See connection parameters at http://www.unityjdbc.com/mongojdbc/ for more details. 
    at mongodb.conn.ServerConnection.processMongoWithUnity(Unknown Source) 
    at mongodb.conn.ServerConnection.executeQuery(Unknown Source) 
    at mongodb.jdbc.MongoStatement.executeQuery(Unknown Source) 
    at mongodb.ExampleMongoJDBC.doQuery(ExampleMongoJDBC.java:222) 
    at mongodb.ExampleMongoJDBC.main(ExampleMongoJDBC.java:66) 

好了,所以我把在自述中查看,發現它提到了code/test/dspec /文件夾以及與模式相關的一些文件。我打開了幾個,它們是所有將它們映射到關係數據類型的集合的高度詳細的xml文件。

我必須寫出其中的一個,還是有辦法自動生成它?

回答

0

我收到Unity團隊的快速回復。

MongoDB的JDBC驅動程序有兩種模式。對於單個集合查詢,它不會構建模式。對於涉及連接或表達式的查詢,它會構建一個模式並默認將其存儲在當前Mongo數據庫的_schema集合中。如果您沒有寫入數據庫的權限,則會引發錯誤。

正如提到的錯誤,您可以設置模式參數是一個本地文件名(如mongo.xml),它會存儲在您的計算機上,而不是在蒙戈數據庫。您也可以使用具有寫入權限的帳戶。

爲了使這項工作,加模式= mongo.xml到您的連接網址是這樣的:

jdbc:mongo://localhost/dbname?schema=mongo.xml?rebuildschema=true 

此過程完成後的第一次,你可以刪除rebuildschema = true或將重建它每一次。

我唯一困惑的是我使用的數據庫不需要身份驗證。我甚至讓用戶擁有寫權限,連接到他,仍然收到上述錯誤。

--edit

我意識到,你也可以只是做jdbc:mongo://localhost/dbname?rebuildschema=true。如果模式尚未創建,則會拋出先前的錯誤。

相關問題