Introduction to MongoDB
1.0 - draft
1.0 - draft
  • MongoDB
  • Getting Started
    • General
      • Database? Collection? Schema?
      • RDBMS? NoSQL?
      • Scale-Up ? Scale - out?
      • JavaScript Object Notation
    • MongoDB
      • 간략한 역사,
    • Manipulating Database
      • MongoShell
      • PyMongo
  • CRUD
    • General
      • Explain()
      • mongoimport
    • Create
      • Mongo Shell
      • PyMongo
      • Exercises
    • Read
      • Mongo Shell
      • PyMongo
      • Exercises
    • Update
      • Mongo Shell
      • PyMongo
      • Exercises
    • Delete
      • PyMongo
      • Exercises
    • Challenging Exercises
      • Exercise 1
  • Index with Geospatial & Text
    • Basic Index
      • Syntax
      • Exercises
    • Geospatial Index
      • Syntax
      • Exercises
    • Text Index
      • Syntax
      • Exercises
    • Challenge
  • Aggregate framework
    • Aggregate Framework
      • Basic
      • Exercises
  • Distributed
    • Replication
      • Setup
        • Configuration File
        • Running Servers
        • Initiation
        • Exercises
      • Concerns
        • Read Concern
        • Write Concern
        • Exercises
    • Sharding
      • Getting Started
      • Setup
  • MongoDB 4.0 Features
    • Multi-Document Transaction
      • Transaction?
      • Basic
      • Exercises
  • Administration
    • Untitled
Powered by GitBook
On this page
  • Manipulate Database/Collection
  • Dictionary

Was this helpful?

  1. Getting Started
  2. Manipulating Database

PyMongo

Manipulate Database/Collection

  • Database List

client.list_database_names()
  • Use a Database

db = client.test_database
# or
db = client['test_database']
  • Collection list

db.list_collection_names()
  • Use a Collection

collection = db['test_collection']
# or
collection = db.test_collection
  • Create a collection

db.create_collection(‘test_collection’)
  • Drop a collection

db.test_collection.drop()
# or
db.drop_collection('test_collection’)
  • Drop a database

client.drop_database(‘test_database’)

Dictionary

  • Using dictionaries to represent documents

import datetime
post = {
"author": "Mike",
"text": "My first blog post!",
"tags": [“MongoDB", “Python", “PyMongo"],
"date": datetime.datetime.utcnow()
}

PreviousMongoShellNextGeneral

Last updated 6 years ago

Was this helpful?