我们可以使用MongoDB进行临时存储吗?

时间:2021-08-11 16:56:23

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!

我的问题是,我们可以使用mongoDB进行临时存储。直到用户退出!

Or is there any other solution for this?

或者还有其他解决方案吗?

2 个解决方案

#1


2  

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:

Redis可能非常适合它,因为它将数据存储在RAM中,请参阅:

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.

由于您使用“mean-stack”标记了您的问题,因此我假设您使用的是Express。有些模块可以帮助您完成您想要做的事情。请参阅express-session文档中的Compatible Session Stores。

Some of the more relevant modules from that list:

该列表中一些更相关的模块:

  • connect-mongo (for Mongo, as you asked)
  • connect-mongo(对于Mongo,正如你所问)
  • connect-mongodb-session (another one for Mongo)
  • connect-mongodb-session(Mongo的另一个)
  • connect-redis (for Redis, which is well suited for that use case)
  • connect-redis(适用于Redis,非常适合该用例)
  • connect-sqlite3 (for SQLite, an embedded RDBMS that you don't have to install)
  • connect-sqlite3(对于SQLite,一个你不必安装的嵌入式RDBMS)
  • session-file-store (for storing session data in files)
  • session-file-store(用于在文件中存储会话数据)
  • or you can use the default in-memory session storage for testing (not suitable for production)
  • 或者您可以使用默认的内存中会话存储进行测试(不适合生产)

#2


0  

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.

我的回答是肯定的,你可以使用mongoDB进行临时存储。您甚至可以为文档设置TTL,使其在一段时间后过期。

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

以下是文档的链接: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.

另一种解决方案是将这种信息存储在数据库中,该数据库仅存储在像Redis这样的内存中。这样你甚至可以获得一些表现。

#1


2  

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:

Redis可能非常适合它,因为它将数据存储在RAM中,请参阅:

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.

由于您使用“mean-stack”标记了您的问题,因此我假设您使用的是Express。有些模块可以帮助您完成您想要做的事情。请参阅express-session文档中的Compatible Session Stores。

Some of the more relevant modules from that list:

该列表中一些更相关的模块:

  • connect-mongo (for Mongo, as you asked)
  • connect-mongo(对于Mongo,正如你所问)
  • connect-mongodb-session (another one for Mongo)
  • connect-mongodb-session(Mongo的另一个)
  • connect-redis (for Redis, which is well suited for that use case)
  • connect-redis(适用于Redis,非常适合该用例)
  • connect-sqlite3 (for SQLite, an embedded RDBMS that you don't have to install)
  • connect-sqlite3(对于SQLite,一个你不必安装的嵌入式RDBMS)
  • session-file-store (for storing session data in files)
  • session-file-store(用于在文件中存储会话数据)
  • or you can use the default in-memory session storage for testing (not suitable for production)
  • 或者您可以使用默认的内存中会话存储进行测试(不适合生产)

#2


0  

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.

我的回答是肯定的,你可以使用mongoDB进行临时存储。您甚至可以为文档设置TTL,使其在一段时间后过期。

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

以下是文档的链接: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.

另一种解决方案是将这种信息存储在数据库中,该数据库仅存储在像Redis这样的内存中。这样你甚至可以获得一些表现。