Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Introduction to MongoDB
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
William Bell
Introduction to MongoDB
Commits
5293015b
Commit
5293015b
authored
2 years ago
by
William Bell
Browse files
Options
Downloads
Patches
Plain Diff
Adding the database name
parent
ddef4566
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
python/create_database.py
+2
-2
2 additions, 2 deletions
python/create_database.py
python/mongo_connect.py
+7
-0
7 additions, 0 deletions
python/mongo_connect.py
with
9 additions
and
2 deletions
python/create_database.py
+
2
−
2
View file @
5293015b
#!/usr/bin/env python3
import
mongo_connect
#
Create
a client connection to the MongoDB database.
#
Get
a client connection to the MongoDB database.
client
=
mongo_connect
.
get_client
()
# Create a new database.
db
=
client
[
'
sales
'
]
db
=
client
[
mongo_connect
.
get_database_name
()
]
# Create a collection.
customers
=
db
[
'
Customers
'
]
...
...
This diff is collapsed.
Click to expand it.
python/mongo_connect.py
+
7
−
0
View file @
5293015b
...
...
@@ -43,3 +43,10 @@ def get_client():
return
None
return
client
def
get_database_name
():
"""
A function to return the MongoDB database name.
"""
return
os
.
getenv
(
'
MONGODB_DB
'
,
'
test
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment