#DbRef is not saving child object automatically in spring data mongodb - mongodb

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

Related

Can I split data into 2 collections in Mongo DB and access the same in SpringBoot

I am using Mongo DB as Database for my springboot application.
I wanted to split the data into 2 collections -primary and auxillary just like how we do it in sql- priamary and secondary table.
Can i do the above and use them in my Springboot application??
Spring boot + Spring data mongo supports multiple collections out of the box.
Just create your POJOs and add the #Document annotation.
You can then define Repository classes (extends MongoRepository) that are then bound to each collection.
Use them to perform nearly any actions on the data.
If you want the data to be in multiple databases, that is also possible, just a bit more complicated.

Copy of huge data from one collection to another collection in Mongodb using spring boot

We are writing a scheduler to take backup of data from one collection to another collection in Mongodb using spring boot.
The data can be 500K to 1Million docs.
Once the copy was completed we should delete the data from old collection. Currently we are using spring data pagination to get the chunks of data and saving to new collection and then deleting.
Is this approach fine or any optimistic approach is suggestible.
As you using spring data with pagination for this task, it means you utilizing container for process documents.
You can trigger set of system command(mongo export and after import delete data from source) from scheduler.
Example like..
SystemCommandTasklet tasklet = new SystemCommandTasklet();
tasklet.setCommand("");
tasklet.setWorkingDirectory("/home/merlin");

Mongo db with springdata configurations

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

Do a MongoDB update with Spring XD & Spring Integration

I'm trying to read a file with Spring XD (source), modify data (processor) and save it in Mongo (sink). I've used the default MongoDB sink which do a save and expect a Spring Data Mongo entity.
But I'd like to do an update with upsert. How can I do ?
Thanks.
The mongo outbound adapter uses MongoTemplate.save() which is already an upsert according to the javadoc.
If you provide your own ObjectId for the same object it will update. You can for example do this during your processor.

Inserting data with relations into Strongloop application

I have a Strongloop application using MongoDB. I have a model with several sub-models, using relations. When I try and insert an object into the database, only the top level data is added. All the related data is ignored. How do I get an entire object with sub-objects into the database?
See the embedded models documentation: http://docs.strongloop.com/display/public/LB/Embedded+models+and+relations