mongodb 多表分页怎么查询?
阿神
阿神 2017-04-28 09:04:38
0
2
772

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

阿神
阿神

闭关修行中......

reply all(2)
Peter_Zhu

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.

迷茫

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!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template