How to avoid that much casts with MongoDb Java-Api - mongodb

HI i'm working with the Java-Api of mongo-db.
I have to cast verry often like this
BasicDBList points = ((BasicDBList) ((BasicDBObject) currentObject.get("poly")).get("coordinates"));
which is not fun. Am i missing something or it is just the way to do it?
i think BasicDBObject should have functions like
BasicDBObject getBasicDBObject(String key)
BasicDBList getBasicDBList(String key)

Unfortunately, the current java driver is not perfect and it is difficult to avoid casting as you mentioned. However, java driver team is working on the next version and as far as I understand it will be completely rewritten.
In one of the mongodb meetup I heard that the new version will make use of asynchronous API, similar to the node driver. I guess we need to sit tight and wait for the next major release.
Alternatives, are (from Mongo Java drivers & mappers performances):
async Java driver
a library built on top of a driver, e.g. Morphia, Jongo, see POJOMappers

Related

Atomic Operations with MongoDB + MongoCXX

I am new to MongoDB, but experienced with C++. I am using the MongoCXX driver within my application. What I need to do now is to increment a counter shared by multiple programs. My thought was that this requires an atomic operation, but I do not see how to do this with MongoCXX.
Searching, I have found that it appears as though a legacy, deprecated API has exactly what I need:
http://mongocxx.org/api/legacy-v1/atomic__word__intrinsics_8h_source.html
In here, I see exactly what I want to do:
WordType fetchAndAdd(WordType increment)
However, I do not see anything like this in the current C++ driver.
http://mongocxx.org/api/mongocxx-3.6.2/annotated.html
Is there any way to do this type of operation with the current API that I am missing?
You can use something like https://docs.mongodb.com/manual/reference/operator/update/inc/.
Some drivers provide wrappers for server commands, but such wrappers aren't strictly necessary because you can always invoke the server commands directly.

How to make an aggregation map in Dash (by plot.ly)

I discovered recently plotly Dash and I am wondering if it's possible to do an aggregation map with it. In my understanding, the only map function is scattermapbox which does not allow such a thing. Am I wrong? If no, is there another way to do it? Maybe another framework? I'm mainly interested in doing a web app which presents side by side an aggregation map and a data grid (datatable in Dash) which interact with each other.
See here for an example of an aggregation map (or map cluster).
As of version 4.1.1 we support the new densitymapbox trace type, which does something quite similar: https://plot.ly/python/mapbox-density-heatmaps/

DocPad and MongoDB

I'm looking for a way to use DocPad with MongoDB. Tried to google about that, but didn't find anything encouraging. Could you please give at least some hints?
Some parts of what I'm developing need to be persisted.
Thanks in advance.
Starting from version 6.55 released last month, DocPad creates a persistent db file in the root of the project called .docpad.db :
https://github.com/bevry/docpad/blob/master/HISTORY.md
I guess it's a first step in the persistent behaviour you need ; the documents may be parsed and inserted in a Mongo database, because behind the scene, DocPad uses QueryEngine which has an API similar to Mongo :
https://github.com/bevry/query-engine
More work is on the way regarding your concern. Have a look at this discussion that deals with the future architecture of DocPad, especially the importer / exporter decoupling :
https://github.com/bevry/docpad/issues/705
I've written some code that reads from Mongodb and returns an object that can be rendered into docs. I've also tried to write some code to provide the backend for basic editing of the database but the regeneration after update is not yet working (although it may be by the time you read this!). See https://github.com/simonh1000/docpad-plugin-mongo

JavaM API for GT.M - SELECT support

I'm wondering if there's any possible way how to use or implement SELECT query into JavaM API for GT.M database system. I'm using version 0.1, since I haven't found any other version ( https://github.com/Gadreel/javam/blob/master/README.md ).
If there's no option yet, could you recommend me any other API for this DBMS, using Java? I know there's some gtm4j ( http://code.vistaehr.com/gtm4j ), but it takes advantage of springframework, which is not convenient for me.
I'm new with GT.M and I just want to test, how to connect to it using Java and use some basic queries. Thanks a lot for your advices.
The database side of GT.M is a hierarchical key-value store, so features like SELECT (I'm guessing you want a full SQL SELECT) needs to be implemented by some framework (either an existing framework or one created by you).
From a quick look at the JavaM API, it seems it only offers/showcase a Java interface to the features offered by GT.M. So I think you would have to implement the SQL SELECT feature yourself, in Java.
That said, it is possible that what you wanted to use a SQL SELECT for can be done easilly using the standard GT.M / JavaM API, so there would be no need to implement a full SQL SELECT.
Actually, you could use M to write a parser for your SELECT command syntax. And would certainly be easier to do with the GTMJI plug-in for full-duplex GT.M/Java communication that FIS have just released.

q.setOrder(...) extremely slow in DataNucleus + MongoDB

I have a latest stable DataNucleus (3.0.1) with MongoDB datastore and JDO implementation.
The collection has around 1M documents.
The "id" field is indexed.
This code takes several minutes to execute:
Query q = pm.newQuery(CellMeasurement.class);
q.setOrdering("id descending");
q.setRange(0, count);
Collection<CellMeasurement> result = (Collection<CellMeasurement>)q.execute();
if I remove the q.setOrdering(...) everything is ok, for count=1000 it takes around a second to load.
It looks like DN does the in-memory reordering, does it have any sense ? MongoDB itself orders instantly by this indexed field, the API supports ordering..
Any idea ? Thanks.
Looking in the log (for any application) would obviously reveal much; in this case what query is actually performed. In this case it would tell you easily enough that ordering is not currently implemented to execute in-datastore.
Obviously anybody could contribute to such codebase that has been open source since its first release. org.datanucleus.store.mongodb.query.QueryToMongoDBMapper method "compileOrdering" is where you need to implement that, and then attach a patch to a JIRA issue when you're done. Thx