简体   繁体   English

在Rails应用程序中从Redis迁移到MongoDB

[英]Migrating from redis to mongodb in ruby on rails application

I am completely new to Mongodb. 我对Mongodb完全陌生。 Earlier I have used redis to store the data that I have processed in my ruby on rails application. 之前,我曾使用Redis将我在ruby on rails应用程序中处理过的数据存储起来。 My redis content is like following: 我的redis内容如下:

 students_<roll_num>: {marks_obtained:..,major_subject:...,..etc.}

Here above students_<roll_num> is the hash where roll_num varies, ie number of hashes depends on the number of students in the class. 上面的students_<roll_num>是其中roll_num变化的哈希,即哈希数取决于班级的学生人数。 I have already put in redis after converting its value to a JSON object. 将其值转换为JSON对象后,我已经放入了redis。 But due to some issues I have to put all those above info in mongodb. 但是由于某些问题,我不得不将所有上述信息放在mongodb中。 I have never used mongo before, so I have no idea how to do this. 我以前从未使用过mongo,所以我不知道该怎么做。 So if anyone helps me with any idea about this I will be really grateful. 因此,如果有人对我有任何帮助,我将不胜感激。

Iterate over your data stored in redis and insert the data in mongodb's collection in following manner : Create a document like : 遍历redis中存储的数据,并按照以下方式将数据插入mongodb的集合中:创建一个文档,如下所示:
j = {students_ = {marks_obtained:..,major_subject:...,..etc.}} j = {students_ = {marks_obtained:..,major_subject:...,.. etc。}}

and then insert the same using : 然后使用插入相同的内容:

db.student.insert( j ) db.student.insert(j)

Where student is the name of collection where you can keep the data in mongodb. 学生是集合的名称,您可以在其中将数据保存在mongodb中。

For further reference you can checkout the tutorial of mongodb 有关更多参考,您可以查看mongodb的教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM