簡體   English   中英

從MATLAB連接到MongoDB

[英]Connection to MongoDB from MATLAB

我想從Matlab R2015a在MongoDB中創建到數據庫的連接。 我已經嘗試過使用C#和Java的驅動程序,但它們似乎都不起作用,我也不知道問題出在哪里。

對於Java:
碼:

javaaddpath('/%path%/mongodb-driver-3.0.0.jar')   
import com.mongodb.*;  
mongoClient = MongoClient();   
db = mongoClient.getDB('myDB');   
colls = db.getCollectionNames();   
coll = db.getCollection('myCollection'); 

錯誤:
對於類“ MongoDB.Driver.MongoClient”,沒有適當的方法,屬性或字段“ getDB”。

對於C#:
碼:

NET.addAssembly('%path%\CSharpDriver-2.0.0\MongoDB.Driver.dll');  
import MongoDB.Driver.*;   
mongoClient = MongoDB.Driver.MongoClient();  
mongoServer = mongoClient.GetServer();  
db = mongoClient.GetDatabase('myDB');  
collection = db.GetCollection('myCollection');  

錯誤:
1.對於類“ MongoDB.Driver.MongoClient”,沒有適當的方法,屬性或字段“ GetServer”。
2.如果我注釋GetServer行,則得到:類'MongoDB.Driver.MongoDatabaseImpl'沒有適當的方法,屬性或字段'GetCollection'。

我不知道我是否缺少某些東西,如果可以使它有用,那將真的很有幫助。

我也嘗試過使用Matlab驅動程序,但是無法創建.dll。 謝謝。

您必須使用以下方法打開客戶端:

import com.mongodb.*;  
mongoClient = MongoClient('myIP', 'myPort');

我在Matlab 2015b中使用Java版本。 我認為您已正確完成導入。 否則,將MongoClient類。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM