本文实例讲述了mongoDB多表关联查询操作。分享给大家供大家参考,具体如下: MonGoose的多表关联查询 首先,我们回忆一下,Mysql多表关联查询的语句: student表: calss表: 通
本文实例讲述了mongoDB多表关联查询操作。分享给大家供大家参考,具体如下:
MonGoose的多表关联查询
首先,我们回忆一下,Mysql多表关联查询的语句:
student表:
calss表:
通过student的classId关联进行查询学生名称,班级的数据:
SELECT student.name,student.age,class.name FROM student,class WHERE student.classId = class.id
Mongoose多表联合查询(还是以众所周知的学生、班级作为实例)
· 表结构的定义(schemas目录下)
1. student表(student.js)
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var StudentSchema = new mongoose.Schema({
name: String,
calssId: {
type: Schema.Types.objectId,
ref: 'class'
},
age: Number,
number: Number,
meta: {
createAt: {
type: Date,
default: Date.now()
},
updateAt: {
type: Date,
default: Date.now()
}
}
});
module.exports = StudentSchema;
--结束END--
本文标题: MongoDB多表关联查询操作实例详解
本文链接: https://www.lsjlt.com/news/51767.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-09
2024-05-09
2024-05-09
2024-05-09
2024-05-08
2024-05-08
2024-05-08
2024-05-08
2024-05-08
2024-05-08
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0