Connecting to MongoDB from MATLAB -


i'm trying use mongodb matlab. although there no supported driver matlab, there 1 java. fortunately able use connect db, etc. downloaded latest (2.1) version of jar-file , install javaaddpath. tried follow java tutorial.

here code

javaaddpath('c:\matlab\myjavaclasses\mongo-2.1.jar')  import com.mongodb.mongo; import com.mongodb.db; import com.mongodb.dbcollection; import com.mongodb.basicdbobject; import com.mongodb.dbobject; import com.mongodb.dbcursor;  m = mongo(); % connect local db db = m.getdb('test'); % db object colls = db.getcollectionnames(); % collection names coll = db.getcollection('things'); % dbcollection object  doc = basicdbobject(); doc.put('name', 'mongodb'); doc.put('type', 'database'); doc.put('count', 1); info = basicdbobject(); info.put('x', 203); info.put('y', 102); doc.put('info', info); coll.insert(doc); 

here stacked. coll supposed dbcollection object, object of com.mongodb.dbapilayer$mycollection class. last command returns error:

??? no method 'insert' matching signature found class 'com.mongodb.dbapilayer$mycollection'.

in tutorial coll variable created explicitly dbcollection object:

dbcollection coll = db.getcollection("testcollection") 

am doing wrong in matlab? ideas?

another minor question colls variable. it's com.mongodb.util.orderedset class , contains list of names of collections in db. how convert matlab's cell array?


update: in addition amro's answer works well:

wc = com.mongodb.writeconcern(); coll.insert(doc,wc) 

a quick check:

methodsview(coll)        %# or: methods(coll, '-full') 

shows expects array:

com.mongodb.writeresult  insert(com.mongodb.dbobject[]) 

try instead:

doc(1) = basicdbobject(); doc(1).put('name', 'mongodb'); doc(1).put('type', 'database'); ... coll.insert(doc); 

note: if using java in matlab, suggest use checkclass , uiinspect utilities yair altman


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -