import pymongo

client = pymongo.MongoClient('URL')

db = client['database_name']
collecction = db['collection_name']

# Print all collection names
print(db.list_collection_names())

# Insert one record
x = collection.insert_one(dict_obj)

# Insert multiple
x = collection.insert_many(list_of_dicts)

# Find one
x = collection.find_one()

# Find all
x = collection.find()

# Return only some fields
for x in collection.find({}, {"id":0 , "name":"John"}):
    print(x)


# Sort
doc = collection.find().sort("field_name", pymongo.ASCENDING)

# Second method of sorting
# 1 - ascending
# -1 - descending
doc = collection.find().sort("field_name", -1)

# Delete one
collection.delete_one(query)

# Delete many
collection.delete_many(query)

# Delete all documents in a collection
collection.delete_many({})

# Drop collection
collection.drop()

# Limimt
x = colleciton.find().limit(5)







import pymongo

client = pymongo.MongoClient('URL')

db = client['database_name']
collecction = db['collection_name']

# Print all collection names
print(db.list_collection_names())

# Insert one record
x = collection.insert_one(dict_obj)

# Insert multiple
x = collection.insert_many(list_of_dicts)

# Find one
x = collection.find_one()

# Find all
x = collection.find()

# Return only some fields
for x in collection.find({}, {"id":0 , "name":"John"}):
    print(x)


# Sort
doc = collection.find().sort("field_name", pymongo.ASCENDING)

# Second method of sorting
# 1 - ascending
# -1 - descending
doc = collection.find().sort("field_name", -1)

# Delete one
collection.delete_one(query)

# Delete many
collection.delete_many(query)

# Delete all documents in a collection
collection.delete_many({})

# Drop collection
collection.drop()

# Limimt
x = colleciton.find().limit(5)







# Print all collection names # Insert one record # Insert multiple # Find one # Find all # Return only some fields # Sort # Second method of sorting # 1 - ascending # -1 - descending # Delete one # Delete many # Delete all documents in a collection # Drop collection # Limimt