search

Home  >  Q&A  >  body text

mongodb 多表分页怎么查询?

mongodb需要查询2个表,进行分页,因为需要限制第二个表的条件。这个怎么写?

阿神阿神2793 days ago774

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-04-28 09:06:38

    Mongodb is not suitable for multi-table queries. Its table structure design ideas are completely different from SQL databases. It is recommended to become more familiar with mongodb’s table structure design to avoid multi-table queries.

    reply
    0
  • 迷茫

    迷茫2017-04-28 09:06:38

    DBRef method association, for example:
    Table one one, table two two,
    db.one.insert({name:"Flying Fox"})
    o = db.one.find({name:"Flying Fox"})[0 ]
    db.two.insert({"title":"Associated one"},one:[new DBRef('one',o._id)])
    db.two.find({title:"Hello China!" })[0].one[0].fetch()
    Use skip and limit to perform paging query, for example:
    db.two.find().sort({"name":1}).skip(10). limit(10);

    There is a lot of information online, the key ones are DBRef, sort, skip, limit!

    reply
    0
  • Cancelreply