As mongodb does not support join and I have the need to search in various business collections, services, and users, I have come up with a solution but I need it to be validated and / or improved.
The flow of the scheme would look like this:
Business = Schema({
name:String
services:[{
type:ObjectId,
ref:'Services'
}],
specialist:[{
type:ObjectId,
ref:'User'
}]
})
User = Schema({
full_name:String
businesses:[{
_id:{
type:ObjectId,
ref:'Business'
},
name:String,
role:String,
is_owner:Boolean
}]
})
Service = Schema({
name:String,
business:{
type:ObjectId,
ref:'Business'
},
specialist:[{
type:ObjectId,
ref:'User'
}]
})
Search = Schema({
text:{
type:String,
index:'text'
},
business:{
_id:{
type:ObjectId,
ref:'Business'
},
name:String
},
services:[{
_id:{
type:ObjectId,
ref:'Service'
},
name:
}],
specialist:[{
_id:{
type:ObjectId,
ref:'User'
},
full_name:String
}]
})
Businesses offer services, services are performed by specialists, and every time a business adds a specialist, the user will have a new business in their data with a specific role.
The idea is that when you create a business, you create a document in Search, and when the business creates services you assign them to the specialists, they will be added to the Search collection. In each modification of this document the text field will be updated with a concatenation of the business name, services and specialists, with this they would have a single collection where to do the searches indexed of text. Any field you are looking for will result in business.
Who has suggestions, both in model and in the solution of the common collection to search.