[英]Get records from two collection in mongoDB using limit and skip
I have two collection called "Order" and "Production Order ". 我有两个集合,分别称为“订单”和“生产订单”。 I have record limit for 40 on each page .
我每页有40条记录限制。 So I need to display total 40 records from both .I have number of question as below mention .
所以我需要同时显示两个记录中的40条记录。
1) Can we get records for two collection from one query ?. 1)我们可以从一个查询中获取两个集合的记录吗? 2) If i will use two query its really hard to display because in case of "Orders " will come 30 and "Production Order "will come 10 and if give limit of 20 for each collection 10 remaining will not display from "Orders "
2)如果我将使用两个查询,则它的确很难显示,因为在“订单”的情况下为30,而在“生产订单”的情况下为10,如果每个集合的限额为20,则“订单”中不会显示剩余的10
possible ways i can think now for your requirement will be 我现在可以根据您的要求考虑的可能方式是
1) Use relationShip ( 1To1
, 1ToMany
, ManyToMany
) and then fetch relative data using .populate()
function of mongoose to get desired data 1)使用关系 (
1To1
, 1ToMany
, ManyToMany
),然后用读取相对数据.populate()
的函数猫鼬以得到所需的数据
2) Or you can use data replication (inCase you done want relationship in Database) 2)或者您可以使用数据复制(如果您确实想要在数据库中建立关系)
"order": {
"_id": "313424535435", // you can add other relevant data according to you need
"production_order": {
"_id": "127342684783" // only add that data which is necessary
}
}
and Vice-versa 反之亦然
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.