Spring Data Mongo: dropCollection doesn't remove collection completely? - spring

Code:
template.dropCollection("products");
After code execution, I see that all documents from collection products were removed, but collection by itself still exists.
So, the question then is how to drop collection completely?
Note: spring-data-mongodb:2.2.10.RELEASE
Mongo DB 4.2.12.

There is a refresh button when you use MongoDB Compass.
Check the collection names, it is already dropped.
System.out.println(template.getCollectionNames());
template.dropCollection("products");
System.out.println(template.getCollectionNames());

Related

Save Related Documents In Mongo Reactive But Not In The Same Collection

I would like to know, how to save related documents in reactive mongo ?. Because I find a code that attempts to do the magic... But when it should save the related document in another collection, it serializes inside the "father" of the relationship let say... I know that in spring data reactive mongo, #DbRef doesnt have support... How could I save the data in a way that, if I query the collection, I see that the attributesare the name of the collection and the generated id instead all of the object attributes ?.
If the pic above is seen, you will see that the attribute "user" is saved as a nested document but not in the corresponding collection. Do I need to hook in another event ?.
I had put a listener onbeforeconvert to scan every time a save operation is to be applied and save the object... How to proceed ?... think I should verify if it has a related doc from another collection and if its nonnull... If the object doesnt have any attr l
Alike, then save it... if not continue the scanning... dunno

Algolia Update Index On Relational Database change with Laravel Scout

I have implemented Aloglia for my Movies table with actors as relational table and it works fine.
Problem:
When I update any movie its also updating algolia index (its good). But how can I update index if I made any change in relational table (for example update an actor of movie).
How to push a specific record manually with laravel scout.
Thanks
The issue itself lies in laravel's events. Whats happening is scout is listening for an 'updated' event which only occurs in laravel when the model object is saved and is dirty (aka value differ from that in the db).
There are two ways you can do this.
The bad lazy way would simply be to add ->touch() to the model prior to save - this will force the updated_at field to update and ultimately trigger the updated event. This is bad as you're wasting a DB query.
The second and preferable way is to register another observer on 'saved' which triggers regardless of whether or not the object is dirty. Likely you either want to check if the model is dirty and only index when its not (to prevent double indexing from the updated event) or just de-register the 'updated' listener that comes in Scout.

How to perform recaching using memcached?

I am using memcached to cache a table records. My code is as follows
Rails.cache.fetch('custom_profiles') do
#custom_profiles=CustomProfile.where(:status=>"Active")
end
But whenever a new record has been added , its not getting updated.I want to update this variable whenever the table got edited. If you have any idea about this please share with me.
You can delete an item from cache like this
Rails.cache.delete('custom_profiles')
You might want to do this in some callbacks or Observers

stop doctrine from fetching related entities

When usually fetching an entity from database with doctrine, you get all the related entities as actual classes, which causes a huge JOIN query, if you have lots of relations.
But sometimes I just want to get the actual object, not all the associated entities, just their IDs.
Is it possible to tell doctrine to just fetch the main entity and leave alone the relations?
Update: Sorry, missed the version: I'm using Doctrine 1.2 on a old project.
By default Doctrine use "lazy-loading": it will not retrieve the associated entities if you do not try to access them.
If you just use the ID of the main entity, it will never retrieves the associated entities.
If you want it to be even more lazy, try using the EXTRA_LAZY param.

JPA Eclispelink - unable to retrieve the last inserted record

I've a problem with JPA EclipseLink.
I've two functions: First, it inserts a row in the database correctly.
The second reads all the values ​​in the same table and show them to you. The problem is that it shows all the values ​​except the last quote, in order to make this appear, I must close and reopen the application.
I also tried to disable the cache does not work.
Do you have any idea on how to solve?
Thanks
How are you querying the quotes? Are you accessing a OneToMany, or using a query?
If accessing a OneToMany, then it could be a caching issues, which you can disable to check,
http://wiki.eclipse.org/EclipseLink/FAQ/How_to_disable_the_shared_cache%3F
A query should always get all objects from the database. Ensure you committed the inserted objects.
The refresh a specific query see,
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Caching#How_to_refresh_the_cache

Resources