ใช้คำสั่งด้านล่างเพื่อเช็คว่า MongoDB Database Tools ทำงานได้ถูกต้องหรือไม่
C:\Program Files\MongoDB
ถ้ามีจะเห็นเป็น folder ชื่อ Tools
และมีโปรแกรม mongostat.exe
อยู่ภายในmongodump --version
mongodump version: 100.9.5
git version: 90481484c1783826fe26ca18bbdcd30e933f3b88
Go version: go1.21.11
os: darwin
arch: arm64
compiler: gc
ถ้าไม่สามารถรันคำสั่งได้ ให้ติดตั้ง MongoDB Database Tools ใหม่ผ่าน homebrew ตามขั้นตอนบนเว็บไซต์ของ MongoDB
ให้ทำการคัดลอก connection string ของ cluster ที่ต้องการใช้งาน จากปุ่ม connect ของ Cluster และเลือก mongo shell
mongosh "mongodb+srv://cluster0.hkdm2.mongodb.net/" --apiVersion 1 --username teerasej
รันคำสั่งด้านล่างเพื่อดูข้อมูลของ MongoDB ที่กำลังทำงานอยู่
mongostat "mongodb+srv://teerasej@cluster0.hkdm2.mongodb.net/"
ระบบจะทำการถาม password ของ user ที่เราใช้งาน ให้ใส่ password ของเราลงไป
จะเห็นข้อมูลถูกแสดงออกมาเรื่อยๆ
เรากำหนดรูปแบบการแสดงข้อมูลของ mongostat ได้ด้วยการใช้ flag --rowcount
และ --host
มีความหมายดังนี้
- --rowcount
คือ จำนวน row ที่จะแสดงข้อมูล
- --host
คือ field ข้อมูลที่เราต้องการให้แสดง
mongostat -o='host' --rowcount=3 "mongodb+srv://teerasej@cluster0.hkdm2.mongodb.net/"
แสดง insert rate
mongostat -o='host,opcounters.insert.rate()=Insert Rate' --rowcount=3 "mongodb+srv://teerasej@cluster0.hkdm2.mongodb.net/"
แสดง insert rate และ query rate, command rate
mongostat -o='host,opcounters.insert.rate()=Insert Rate,opcounters.query.rate()=Query Rate,opcounters.command.rate()=Command Rate' --rowcount=3 "mongodb+srv://teerasej@cluster0.hkdm2.mongodb.net/"