Home
Sign Up
Sign In
V2EX
›
问与答
用mongo的同学,请问在一个document里要查询另外一个document怎么弄?
goofansu
·
Dec 12, 2013
· 2824 views
This topic created in 4714 days ago, the information mentioned may be changed or developed.
情况如下:
1. A有个bid对应B的id,
2. 查询A的时候想获取关联的B,拿B里面的其他字段。
场景:
我是在做统计,统计结果要用B里面一个字段作为描述,现在只能先把A统计完,再到B里面按bid一个个拿。
有没有先进点的方法?
document
bid
统计
2 replies
•
1970-01-01 08:00:00 +08:00
SevenJ
Dec 12, 2013
1
如果是用mongoose的话, schema定义里头可以
bid: ObjectId, ref: 'B'
query时加populate(‘字段X')
goofansu
OP
Dec 12, 2013
2
@
SevenJ
额,纯shell
你的这个做法是不是就等于是在A里面定义了一个B的ref?
About
·
Help
·
Advertise
·
Blog
·
API
·
FAQ
·
Privacy
·
Solana
·
4393 Online
Highest 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 35ms ·
UTC 03:26
·
PVG 11:26
·
LAX 19:26
·
JFK 22:26
♥ Do have faith in what you're doing.
❯