SQL + PyMongo

DODO·2026년 3월 14일

PyMongo

1.Setting - MongoDB Atlas

2.Using with Colab

➀make Collection
➁put Document : insert_one, insert_many
➂search Data: find(), find_one()
➃Projection
➄sort() & limit()
➅Update: update_one(), update_many()
➆delete: delete_one()
➇delete Collection: drop


➀➁➂➃➄➅
temp_collection = db.temp_movies
my_movie = { "title": "My Test Movie",
"year": 2023, "genres": ["Action", "Comedy"] }
result_one = temp_collection.insert_one(my_movies)
display(movies.find_one({“title”:”The Great Train Robbery”))
my_movie_list=[{content},{content},{content}]
result_many= temp_collection.insert_many(my_movies_list)
for doc in temp_collection.find({content}):
display(doc)

➃➄➅
for doc in movies.fine({content},{content}).sort(,-1).limit(5)
display(doc)
uqdate_result_one= \ temp_colletion.update_one(
{content}, {content})
update_result_many= \ temp_collection.update_many(
{content}, {content})
delete_result_one= temp_collection.delete_one({content})
temp_collection.drop()


3. Aggregation

Step . $match = WHERE

① eq : = ② $gte: >= ③ $lte: <= ④ $gt: > ⑤ $lt: < ⑥ne: != ⑦ $in: in ⑧ $nin: not in

Logical Operators

① $and ② $or ③ $nor

$goup

① $sum ② $avg ③ $min ④ $max

$project = SELECT

review

0개의 댓글