Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to return raw json directly from mongodb query in java?


Asked by Edgar McPherson on Dec 08, 2021 Java



How to return raw JSON directly from a mongodb query in Java? The Map object is then converted to JSON by Spring MongoData before it is returned to the browser. Is it possible to directly return the raw json from MongoDb without going through the intermediate conversion steps? 1. Using the CollectionCallback on MongoTemplate
And,
MongoDB comes with “ com.mongodb.util.JSON ” class to convert JSON data directly to a DBObject. For example, data represent in JSON format : To convert it to DBObject, you can code like this : See a full example to convert above JSON data to a DBObject, and save it into MongoDB.
Besides, Some applications may need to store raw (unmodified) JSON because there is uncertainty in how the data will be structured. There are hundreds of XML-based standards.
In fact,
It allows you to write mongo queries in java (or scala) code using the same syntax as that of mongo command shell. To be more specific, you can write mongo queries in string format. It also supports advance features such as aggregation pipeline.
One may also ask,
To access documents or entities stored in a MongoDB you can create a respected repositories. Look at the @Query annotations in the MovieRepository interface, It is used to define your queries using @Query annotation along with respected methods, Which simplifies the underline for MongoDB query operations.