هذا أحد الإجرائين اللذين يعملان على قاعدة البيانات بدلاً من مجموعة واحدة — لذا لا توجد collection لتمريرها. الإجراء الآخر هو overview.
await storage.run({ action: "collections" });
// [{ name: "users", count: 1204 }, { name: "orders", count: 88311 }]storage.run(action="collections")
# [{"name": "users", "count": 1204}, {"name": "orders", "count": 88311}]العدد تقديري
اقرأ البيانات الوصفية، لا المستندات واحداً واحداً
الحصول على عدد دقيق لمجموعة كبيرة يعني قراءتها. ولرقم ستتخذ قراراً بناءً عليه، استخدم count مع مرشح؛ أما لسؤال «ما حجمها تقريباً؟» فالتقدير هو المطلوب وهو مجاني.
تُستثنى مجموعات النظام
تُرشّح المجموعات الداخلية، لذلك ما يعود هو ما وضعته أنت فيها. إذا أنشأت مجموعة ولا تراها هنا، فهذه علامة على اتصالك بقاعدة بيانات مختلفة — انظر إلى مسار URI في connect().
const collections = await storage.run({ action: "collections" });
if (!collections.length) {
// Either it is empty, or the connection landed on the wrong database.
// The database is read from the path of the URI: …/mydb
}collections = storage.run(action="collections")
if not collections:
# Either it is empty, or the connection landed on the wrong database.
# The database is read from the path of the URI: …/mydb
pass