search

Home  >  Q&A  >  body text

mongoose - mongodb怎么实现一对多的功能。

就是两个mongodb的表,或者是mongoose的表,然后要实现一对多的对应关系。怎么实现呢?可以举个例子吗?我找了很多文档,都没看懂。谢谢各位大神。

高洛峰高洛峰2793 days ago791

reply all(2)I'll reply

  • 迷茫

    迷茫2017-05-02 09:21:41

    I don’t know what you want, but one-to-many doesn’t seem to comply with database logic. For example, if you retrieve a field and the corresponding value is different, how does the program know which value to return to you?
    But since you want to implement one-to-many in mongo, the key-value structure can achieve similar functions. You can set value as an array, so that one key can correspond to multiple values. The database returns an array, and you can find the results you want in the code.

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-02 09:21:41

    I don’t know what language the poster uses. Some mainstream development languages ​​have corresponding expansion packs.
    For example, there is the Mongoid gem package in Ruby, which encapsulates many common methods and can easily meet your needs.
    You can find out whether there is a corresponding library for the development language you are using.

    reply
    0
  • Cancelreply