My app is a korean-english dictionary that I am writing on node.js using MongoDb. The problem is to organize database so I can have korean-english and english-korean direction with the same words. In MySQL I would use table of all words and many-to-many connection table with words references.
For example I have
A is C
A is D
B is C
Translations for A are C, D - one direction
Translations for C are A, B - another direction
How do I organize database in Mongo?
Asked
Active
Viewed 501 times
3

staskjs
- 97
- 6
1 Answers
1
if i understood you right.
assuming you have this collection.
db.collection({'en': 'word_en', 'kr':'word_kr'})
if you want to search en
eqvivalent of 'korean' word just write:
db.collection.find({'kr': 'word'})
and vice versa
db.collection.find({'en': 'word'})
do not forget create indexes for collection.
Also, make sure that your indices aren't unique, so you can be able to add multiple references. So in extension of your example, you would get something like this:
db.collection({'en': 'A', 'kr':'C'})
db.collection({'en': 'A', 'kr':'D'})
db.collection({'en': 'B', 'kr':'C'})
And when you want translations for A
:
db.collection.find({'en': 'A'})
you get an array with C and D. Similar with moving from C

nevi_me
- 2,702
- 4
- 24
- 37

Dmitry Zagorulkin
- 8,370
- 4
- 37
- 60