Closed platomaniac closed 8 years ago
Thanks for reporting. Mostly done with adding this, will have it released here tomorrow.
Please re-run the installation command at the top of the readme to update, and let me know if you hit any problems.
Thanks a lot for the prompt update. The connection to Azure with mongo-uri works now. The FindDocuments
function also worked. However I am still facing problem with few important functions.
InsertDocument[coll, {"a" -> 1, "b" -> 22}]
returning $Failed[MongoDBLink
PrivategetN[]]
and throws the following on MMA 11:
Java::argx: Method named insert defined in class com.mongodb.DBCollection was called with an incorrect number or type of arguments. The arguments, shown here in a list, were {{« JavaObject[com.mongodb.BasicDBObject]»},WriteConcern
ACKNOWLEDGED}.`
and when I tried UpdateDocument[coll, {"x" -> 3.0}, {"$set" -> {"x" -> 13.0}}]
returning $Failed[MongoDBLink
PrivategetN[]]
Java::argx: Method named update defined in class com.mongodb.DBCollection was called with an incorrect number or type of arguments. The arguments, shown here in a list, were {« JavaObject[com.mongodb.BasicDBObject]»,« JavaObject[com.mongodb.BasicDBObject]»,False,False,WriteConcern
ACKNOWLEDGED}.`
As expected DeleteDocument
also throws similar errors. Also s there is any possibility to bulk insert data in mongo than using mapping constructs like this InsertDocument[coll, {"a" -> #, "b" -> 2 #}] &/@ Range[5]
?
Thanks again for the nice package.
Progress at least!
I'm able to run those commands without problem here...
Any chance you have an ancient mongo java driver (2.0) in your class path? (Try Select[JavaClassPath[], StringContainsQ[#, "mongo"] &]
.) The syntax used in this package was added in 2.1, so if you have an old version it could be preempting the required version.
Can you also please check after loading <<MongoDBLink`` that
WriteConcernACKNOWLEDGED
returns <<JavaObject[com.mongodb.WriteConcern]>>
?
Re: bulk inserts: no, not yet. You could evaluate this to add support for it:
InsertDocument[collection_Collection,
documents : {{(_Rule | _RuleDelayed) ..} ..},
opts : OptionsPattern[]] :=
Total[InsertDocument[collection, #, opts] & /@ documents]
Usage:
In[100]:= InsertDocument[coll, {
{"a" -> 100},
{"a" -> 101}
}
]
Out[100]= 0
Note that writes are not very efficient at the moment because serializing Mathematica "documents" calls in and out of java repeatedly. (Compare to deserializing for reads, which is done in Java and is fast.) If this is a major use case, let me know and I'll move it to Java.
After loading `<<MongoDBLink`` I have checked
WriteConcern`ACKNOWLEDGED
unfortunately it returns back WriteConcern
ACKNOWLEDGED` and not the JAVA object you expected.
Without loading `<<MongoDBLink`` my classpath seems to be all right as it correctly points to
Needs["JLink`"];
Select[JavaClassPath[], StringContainsQ[#, "mongo"] &]
C:\ProgramData\Mathematica\Applications\MongoDBLink\Java\mongo-java-\driver-3.2.1.jar
I will shortly try in Linux too.
I am considering of using this package as a pretty handy tool for a big project where plenty of write operations will arise. Of course read will be much more than write if I compare. It will be of much help if some JAVA side brushing up could make this super handy package act as a fast duplex communication interface between MMA and mongodb.
Thanks a lot for this speedy cooperation.
Ah, okay, that's the problem. The other forms of OpenConnection
loaded the WriteConcern class, but the URI form didn't. Please update again and I think it will work -- let me know.
Opened #12 for speeding up writes. Hopefully can do by the end of the week.
My bad the update had some glitches. Now it works fine. Will start experimenting with some real data now. Looking forward to the update 👍 👍
I am failing to connect to a remote mogoDB service from Azure. Though using standard java driver I can connect via the same mongo-uri.
ReinstallJava[ClassPath->"mongo-java-driver-3.2.2.jar"]; mongo=JavaNew["com.mongodb.MongoClient", JavaNew["com.mongodb.MongoClientURI","mongodb://username:passwd@host:10250/?ssl=true"]];
The azure mongo-uri is like this:
mongodb://username:passwd@host:10250/?ssl=true
Now I can use the connection
mongo
and get the db and the collection in it.db=mongo@getDB["dbName"]; collection=db@getCollection["colName"]
It will be great if we could support the mongo-uri as many cloud database like Azure use this to connect remotely to their mongoDB service instance. However a change in the JAVA source code may be necessary.
I first raised this issue here in mathematica stackexchange and opening an issue as the proposed suggestion in the comment failed to work with mongo-uri.