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.
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: [
]
}
teacher
{
_id:ObjectID(<MongoDB ID>),
id:<faculty ID>,
name:<name>,
courses:[ course_id1, course_id2 ]
}
course
{
_id:ObjectID(<MongoDB ID>),
id:<course number>
}
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.