GetDatabaseCollection returns a collection if one exists, otherwise error.
(scopeName, collectionName string)
| 2210 | |
| 2211 | // GetDatabaseCollection returns a collection if one exists, otherwise error. |
| 2212 | func (dbc *DatabaseContext) GetDatabaseCollection(scopeName, collectionName string) (*DatabaseCollection, error) { |
| 2213 | if base.IsDefaultCollection(scopeName, collectionName) { |
| 2214 | return dbc.GetDefaultDatabaseCollection() |
| 2215 | } |
| 2216 | if dbc.Scopes == nil { |
| 2217 | return nil, fmt.Errorf("scope %q does not exist on this database", base.UD(scopeName)) |
| 2218 | } |
| 2219 | collections, exists := dbc.Scopes[scopeName] |
| 2220 | if !exists { |
| 2221 | return nil, fmt.Errorf("scope %q does not exist on this database", base.UD(scopeName)) |
| 2222 | } |
| 2223 | collection, exists := collections.Collections[collectionName] |
| 2224 | if !exists { |
| 2225 | return nil, fmt.Errorf("collection \"%s.%s\" does not exist on this database", base.UD(scopeName), base.UD(collectionName)) |
| 2226 | } |
| 2227 | return collection, nil |
| 2228 | } |
| 2229 | |
| 2230 | func (dbc *DatabaseContext) GetDefaultDatabaseCollection() (*DatabaseCollection, error) { |
| 2231 | col, exists := dbc.CollectionByID[base.DefaultCollectionID] |