VinoPravin
VinoPravin

Reputation: 987

Can we use MongoDB for Temporary storage?

I want to create a database which stores the user data for a temporary period of time (i.e) Until the user logout.

Once the user logged out, I want all the details they are provided to get deleted.

My question is, can we use mongoDB for temporary storage. Until the user logout!

Or is there any other solution for this?

Upvotes: 3

Views: 3856

Answers (2)

rsp
rsp

Reputation: 111446

You can use any database to do that. Just delete the data when the user logs out.

Redis may be a good fit for that because it stores the data in RAM, see:

But really any database can do it. You will just have to remove the data on logout.

Since you tagged your question with "mean-stack" then I assume that you're using Express. There are some modules that can help you with what you're trying to do. See the Compatible Session Stores in the express-session documentation.

Some of the more relevant modules from that list:

Upvotes: 2

alejdg
alejdg

Reputation: 2473

My answer is yes, you can use mongoDB for temporary storage. You can even set a TTL for the document so it will expire after an amount of time.

Here is the link for the documentation: https://docs.mongodb.com/manual/tutorial/expire-data/

Another solution would be to store that kind of information in a database that persists only in memory like Redis. That way you could gain some performance even.

Upvotes: 2

Related Questions