怎么用mongodb或者mongoose库建立文档引用
習慣沉默
習慣沉默 2017-04-28 09:04:59
0
2
596

比如:一名学生(学号,名字,性别,年龄)教师(教工号,名字)选课信息(学号,课程号,教工号,成绩)

请问怎么用mongodb模块建立这三个的关系??

習慣沉默
習慣沉默

reply all(2)
给我你的怀抱

MongoDB creates index: db.collection.createIndex( { name: 1 } )
db - is a database
collection - is a table (relative to mysql)

About database establishment, I will write like this: (for reference only)
student
{
_id:ObjectID(<MongoDB ID>),
id:<student ID>,
gender: <gender>,
age: <age>,
name: <name>,
course_ids: [

  course_id1:{
     mark: <成绩>,
     teacher_id: <教工号> 
  },
  course_id2:{
     mark: <成绩> 
  }

]
}

teacher
{
_id:ObjectID(<MongoDB ID>),
id:<faculty ID>,
name:<name>,
courses:[ course_id1, course_id2 ]
}

course
{
_id:ObjectID(<MongoDB ID>),
id:<course number>
}

Ty80

Mongodb has DBRef as a document reference, which can record the document location of other collections. However, this reference is not the concept of a foreign key in the SQL database. It can only record the collection name and ID number of the referenced document. No other operations can be attached, and it cannot even perform some operations when the referenced document changes or is deleted. All mongodb establishment of reference relationships is mainly done through programs rather than databases.

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