I have records with _class attribute in mongodb. Is there any method to ignore this class when retrieve data using spring data.
You can load that using any class, "_class" doesnt impact that
Related
I have an existing MongoDB without the _cls field in the documents.
Data will continue to enter the DB during the lifetime of the DB, data is added through Morphia which doesn't add the _cls field automatically.
It seems not the best idea to add a _cls field to Morphia Entities.
Do you have a better idea how to make the data coming from morphia better fit (have the _cls field) in mongo documents?
Edit:
*I am using flask server in python with mongoengine which require the field
I saw the solution for using #PreSave in Morphia, it is a good Idea and I will use it if another solution is not found. ** I am looking for a solution in the Python side**. you aren't always able to change the data insertion
You could use Morphia’s #PreSave annotation to ‘tweak’ the JSON document prior to it being saved to the database. You could then just inject the _cls field and value without having to declare a field in your Java class
Is it possible to enforce a Mongo collection to hold a single document only using Spring data mongo repository ? Is it possible via MongoRepository ?
I write a big aggregate query for mongodb, now I try to translate it in Spring Data Mongodb API, and it's very complicated, and spring data api did not help me a lot.
So like with #Query annotation, is it possible to just specify my raw aggregate query in text and map my field with Spring Data (or just Mongodb Java driver) ?
I won't c/p my aggregate request because, it's not the purpose of my question.
I found a solution by using MongoDB java driver, which is available through Spring Data :
DBCollection collection = mongoTemplate.getCollection("myCollection");
and I used BasicDBObject from this solution : MongoDB aggregation with Java driver
I want to read around 1 million documents from my mongodb database and I am using spring data mongodb. I do not want to read all of 1 million data at once for performance reasons. Is there any way in spring-data-mongodb to do this. In raw java driver we have DBCursor.
One way i know is using pagination through repositories. Is there any other way in latest versions of spring data mongodb?
Yes. You can use pagination with spring data mongodb. MongoRepository extends from PagingAndSortingRepository which means you can call findAll(Pagable) and provide page information.
Alternatively, you can use mongoOperations/mongoTemplate to get a DBCollection reference, and then call find() on the collection and that will return you the DBCursor you want.
I am currently using GA release of Spring Data MongoDB framework and #DbRef is not saving child object automatically in spring data mongodb. Can you tell me how can i make it work?
Saving child objects is not built into Spring Data MongoDB so you have to do it manually or you can extend AbstractMongoEventListener as I described it in my article: Spring Data MongoDB cascade save on DBRef objects