mongodb - Mongo获取多个集合查询
问题描述
我正在练习并且对 MongoDb 数据库查询非常陌生。我有三个集合数据。一个系列是客户,一个系列是客户的包,最后一个系列是客户的布。他们每个人都与id连接。我正在使用MongoDB 包进行连接和查询。我的目标是当客户的布料被出售时,它会从我想要获取客户信息的 bagId 中查找 bagId。.我真的不知道如何查询这个 MongoDB。
我的客户数据是这样的
_id:058585821193645242
accountNumber:"GI-325202"
address:"Calfornia"
city: "Calfornia"
email: "customer@gmail.com"
firstName:"John"
lastName:"doe"
name: "John doe"
phoneNumber: "0000-000"
customerId: 1200 // this id is connected with my bag collection
这是包系列
bagId:119
customerId:1200 // this my customer Id
这是我的布系列
clothId: 123
bagId: 119
status: sold. // this is my cloth status
clothId: 123
bagId: 119
status: not sold. // this is my cloth status
解决方案
请先学习mongodb数据建模,不要与RDBMS相关。
- https://docs.mongodb.com/manual/tutorial/model-embedded-one-to-one-relationships-between-documents/
- https://docs.mongodb.com/manual/tutorial/model-embedded-one-to-many-relationships-between-documents/
- https://docs.mongodb.com/manual/tutorial/model-referenced-one-to-many-relationships-between-documents/
推荐阅读
- http - 如何从 vbscript 获取电报机器人 getUpdates json 并读取它
- python - 如何强制 pythons 格式方法在评估值时放置值
- powershell - Nuget 包 init.ps1 脚本和 PackageReference 修改
- sql-server - 有没有办法保护 SSRS 报告密码?
- mysql - 如果没有日期记录,如何处理 where Date
- facebook - 在 Facebook Messenger 中消失/更改私人信息
- javascript - 使用 React.js 在 if 语句中将变量值作为条件传递
- python - Python multiprocessing.Pool() 给出错误
- html - 边界半径间隙
- java - 使用 Google 上的操作从 webhook 请求中获取连接池