Inserting Documents with MongoDB Java driver version 3 - mongodb-java

We have some applications using MongoDB with Java driver (2.x version). In our apps we insert objects using the BasicDBObject such as:
BasicDBObject doc = new BasicDBObject("title", "MongoDB").
append("description", "database").
append("likes", 100);
Looking at the docs of the Java Driver 3.0 I can see that another approach is used:
Document doc = new Document("name", "MongoDB")
.append("type", "database")
.append("count", 1)
.append("info", new Document("x", 203).append("y", 102));
Is the BasicDBObject deprecated in the version 3.0? (hope not, we have to change all our code)

You can continue to use DBObject with the 3.0 API. Existing code should (mostly) work when bumping to the 3.0 driver. There are various advantages to switching to the new APIs but that's something you can do at your leisure over time.

Related

How to configure maxDegreeOfParallelism for cosmosdb in Springboot?

I want to configure the CosmosQueryRequestOptions.maxDegreeOfParallelism while using the CosmosRepository. I didn't find any documentation around it.
This blog shows how to configure and use this setting through a custom client, but I want to use the repository instead. https://medium.com/#middha.nishant173/improve-query-performance-with-azure-cosmosdb-java-sdk-v4-db1fc54cb484
CosmosQueryRequestOptions is implementation detail for Spring Data Cosmos SDK, so customers cannot set it through spring application.
This can be implemented as a new feature, and can be exposed through application.properties via query.maxDegreeOfParallelism - which customers can opt in if they want.
Default value for maxDegreeOfParallelism is 0, which is the right value for single partition queries. For cross partition queries in the current SDK version, you can get the cosmosClient through spring boot applicationContext and run the query directly against the client. This example shows how to do it - https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/cosmos/azure-spring-data-cosmos-test/src/test/java/com/azure/spring/data/cosmos/repository/integration/PageableAddressRepositoryIT.java#L144

can I use old spring-data-elasticsearch to connect to new elasticsearch?

Currently we are on spring-data-elasticsearch 3.2.6 + elasticsearch 6.8.
We are moving to new elasticsearch 7.x. Do I have to update spring-data-elasticsearch to 4.x? We only use ElasticsearchRepository in spring-data-elasticsearch. And we don't need to use any new feature in elasticsearch 7.x.
If we are moving to elasticsearch 8.x in the future, do I need update spring-data-elasticsearch ?
Update:
What Elasticsearch client does Spring-Data-Elasticsearch use under the hood?
All methods in the `ElasticsearchRepository` are deprecated. What should do I use?
I found some discussions in above threads. Here is my summary.
Operations with Templates:
ElasticsearchTemplate implements ElasticSearchOperation. It uses TransportClient(which is deprecated in ES 7 and has been removed in ES8)
ElasticsearchRestTemplate implements ElasticSearchOperation. It uses high level client(which is deprecated in ES 7.16.0. It will be removed in future. #Deprecated(since = "7.16.0", forRemoval = true) )
ReactiveElasticsearchTemplate implements ReactiveElasticsearchOperations. It uses Reactive Client.
Repository
ElasticsearchRepository uses TransportClient as default. All methods in the ElasticsearchRepository are deprecated now.
Reactive Elasticsearch repository builds on ReactiveElasticsearchOperations.
Due to underlying TransportClient or HigLevelRestClient has been deprecated, can I conclude that the correct way is to use Reactive Client(ReactiveElasticsearchTemplate or Reactive Elasticsearch repository) ?
The new Elasticsearch would be 8.
Val already put the link to the compatibility matrix in his comment.
Version 3.2.6 is pretty outdated (March 25 2020) and out of support since October 2020.
The first thing you can try is to see if your application works with a 7 cluster - although I doubt that, I can't tell you exactly what had changed in the API, but there was quite some stuff.
What you should not do is putting newer Elasticsearch libraries on the classpath than the ones that Spring Data Elasticsearch was built with, this will in most cases make problems.
But I'd recommend to upgrade your application anyway and keep it regularly up to date.
As for future upgrade to version 8: It is possible to send a compatibility header in your requests (this can be done in Spring Data Elasticsearch 4) and the Elasticsearch cluster should respond in a format that is compatible with a client expecting version 7. I wrote should, because it does not conform to this in every case - I reported one case that is fixed now. But I wouldn't rely on that.
Again, please update your application and keep it up to date, not only because of Spring Data Elasticsearch, but also because these updates always include bug and/or security fixes.

Why was Jasper support dropped out from Spring Framework 5.x?

We have been using Jasper with Spring Boot for our project's reporting feature but according to the Spring Framework 5.x release documentation Jasper support has been dropped out.
May I know why this has been done?
They have recommended to stay on Spring Framework 4.3.x in case we need Jasper support.
What if we want to upgrade to Spring Framework 5.x and still use Jasper, is there any alternative for doing so ?
Both parts of your question are answered in the JIRA ticket that tracked the support being dropped.
May I know why this has been done?
After some investigation, the new Exporter API in JasperReports is designed for upfront configuration in the form of ExporterInput / ExporterOutput objects, not lending itself to the piecemeal approach in Spring's JasperReports view class hierarchy and in particular not to the declarative configuration style typically used there. Even aside from that, we'd have to redesign our entire JasperReports view support in an severely incompatible way, due to the wide-ranging API changes across the JasperReports configuration model.
What if we want to upgrade to Spring Framework 5.x and still use Jasper, is there any alternative for doing so?
As a consequence, we rather recommend native use of the JasperReports API in Spring MVC handler methods, generating reports from specifically designed RESTful endpoints.
I had to upgrade to Spring 5 and this worked for me:
#GetMapping(value = "/report1")
public void getPdf(HttpServletResponse response) throws JRException, IOException {
InputStream jasperStream = this.getClass().getResourceAsStream("/jasperreports/HelloWorld1.jasper");
Map<String,Object> params = new HashMap<>();
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(jasperStream);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JREmptyDataSource());
response.setContentType("application/x-pdf");
response.setHeader("Content-disposition", "inline; filename=helloWorldReport.pdf");
final OutputStream outStream = response.getOutputStream();
JasperExportManager.exportReportToPdfStream(jasperPrint, outStream);
}
We have upgraded to Jaspersoft 6.8.1(Open Source) and Jaspersoft Pro 7.3.1 with Spring 5.1.20. We found below problems while upgrading:
Initially Font Extensions were not working. So, we created it
again using Jaspersoft 7.3.1 Studio.
There was a js file called jrs.configs.js which got introduced in Jasperreports Highcharts library was not loading because of which our Highcharts were not loading in embedded environment. We have put the file in the location where it was searching inside our web app. After that, everything is working.

Can someone provide me an example for Spring Data Couch Base 2.x client to store and retrieve data in Key Value format from couch base server?

My current project uses spring data couch base 1.2.3 Release version where CouchBaseClient object will be there to retrieve save/get data in key value format from couch base server/cluster/bucket. Now we are planning to upgrade spring data couch base version to 2.x, but CouchBaseClient object has been deleted in 2.x instead bucket/cluster beans are available. Bucket object doesn't have any APIs/methods to save/get data in key value format [ i might be wrong, not sure] so request to help me to find out how to proceed further is there a way in 2.x to store data in key value format?
we have plans to upgrade spring boot version to 1.4.4.release as well so if there are any others ways to interact easily with couch base server, please let me know.
My project env info:
Spring boot 1.2.3
Java 1.8
Thanks,
Satish
This is more a factor of the underlying SDK being of a different generation (2nd generation of Couchbase SDKs, where most methods align in all languages/SDKs and the whole API has been made more coherent).
This generation of SDK exposes objects closer to the reality of the Couchbase cluster: Cluster object to connect to the nodes and perform cluster-wide operations, then Bucket to perform data operations.
Spring Data Couchbase 2.x builds on that. In your configuration you'll choose which Bucket to use (see the docs) and as such you'll also be able to inject that Bucket instance if you really need to.
Note that Spring Data Couchbase offers several layers of abstraction on top of the SDK: repositories for CRUD operations around an entity type, then CouchbaseTemplate that offers individually typed operations but is still capable of marshalling to JSON (the SDK is accessible from CouchbaseTemplate).
On the other hand, with the SDK you have to marshall to JSON yourself, either as a JsonObject map-like structure (default) or a String (in which case you need to store and retreive a RawJsonDocument). Working with these Document types is all explained in the SDK's documentation.

How to query Couchbase 1.8 JSON?

I am new to couchbase.
I am taking a look at the new Couchbase 2 beta version and the JSON docs, indexes, views, querys look just great.
Thing is that I have to develop under version 1.8 and I can't get the way to query my JSON objects. I am the using ruby client.
Thanks.
I suppose that Couchbase 1.8 does not support this functionality.

Resources