ใช้เงื่อนไขในกฎความปลอดภัยของฐานข้อมูลเรียลไทม์

จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ

คู่มือนี้สร้างขึ้นจากคู่มือ การเรียนรู้ภาษาหลักของกฎความปลอดภัยของ Firebase เพื่อแสดงวิธีเพิ่มเงื่อนไขให้กับกฎความปลอดภัยของฐานข้อมูลเรียลไทม์ของ Firebase

องค์ประกอบหลักของกฎความปลอดภัยของฐานข้อมูลเรียลไทม์คือ เงื่อนไข เงื่อนไขคือนิพจน์บูลีนที่กำหนดว่าควรอนุญาตหรือปฏิเสธการดำเนินการเฉพาะ สำหรับกฎพื้นฐาน การใช้ตัวอักษร true และ false เนื่องจากเงื่อนไขทำงานได้ดี แต่ภาษากฎความปลอดภัยของฐานข้อมูลเรียลไทม์ให้วิธีเขียนเงื่อนไขที่ซับซ้อนมากขึ้น ซึ่งสามารถ:

  • ตรวจสอบการรับรองความถูกต้องของผู้ใช้
  • ประเมินข้อมูลที่มีอยู่กับข้อมูลที่ส่งใหม่
  • เข้าถึงและเปรียบเทียบส่วนต่าง ๆ ของฐานข้อมูลของคุณ
  • ตรวจสอบข้อมูลขาเข้า
  • ใช้โครงสร้างของแบบสอบถามขาเข้าสำหรับตรรกะความปลอดภัย

การใช้ตัวแปร $ เพื่อจับส่วนเส้นทาง

คุณสามารถจับภาพบางส่วนของเส้นทางสำหรับการอ่านหรือเขียนโดยการประกาศตัวแปรการดักจับด้วย $ นำหน้า สิ่งนี้ทำหน้าที่เป็นไวด์การ์ดและเก็บค่าของคีย์นั้นเพื่อใช้ในเงื่อนไขของกฎ:

{
  "rules": {
    "rooms": {
      // this rule applies to any child of /rooms/, the key for each room id
      // is stored inside $room_id variable for reference
      "$room_id": {
        "topic": {
          // the room's topic can be changed if the room id has "public" in it
          ".write": "$room_id.contains('public')"
        }
      }
    }
  }
}

ตัวแปร $ แบบไดนามิกยังสามารถใช้ควบคู่ไปกับชื่อเส้นทางคงที่ ในตัวอย่างนี้ เรากำลังใช้ตัวแปร $other เพื่อประกาศ กฎ .validate ที่รับรองว่า widget ไม่มีลูกนอกจาก title และ color การเขียนใด ๆ ที่จะส่งผลให้มีการสร้างลูกเพิ่มเติมจะล้มเหลว

{
  "rules": {
    "widget": {
      // a widget can have a title or color attribute
      "title": { ".validate": true },
      "color": { ".validate": true },

      // but no other child paths are allowed
      // in this case, $other means any key excluding "title" and "color"
      "$other": { ".validate": false }
    }
  }
}

การรับรองความถูกต้อง

รูปแบบกฎความปลอดภัยที่พบมากที่สุดรูปแบบหนึ่งคือการควบคุมการเข้าถึงตามสถานะการรับรองความถูกต้องของผู้ใช้ ตัวอย่างเช่น แอปของคุณอาจต้องการอนุญาตให้เฉพาะผู้ใช้ที่ลงชื่อเข้าใช้เขียนข้อมูลได้

หากแอปของคุณใช้การตรวจสอบความถูกต้องของ Firebase ตัวแปร request.auth จะมีข้อมูลการตรวจสอบสิทธิ์สำหรับข้อมูลที่ลูกค้าร้องขอ สำหรับข้อมูลเพิ่มเติมเกี่ยวกับ request.auth โปรดดู เอกสารอ้างอิง

Firebase Authentication ผสานรวมกับ Firebase Realtime Database เพื่อให้คุณควบคุมการเข้าถึงข้อมูลแบบรายผู้ใช้โดยใช้เงื่อนไข เมื่อผู้ใช้ตรวจสอบสิทธิ์แล้ว ตัวแปร auth ถูกต้องในกฎกฎความปลอดภัยของฐานข้อมูลเรียลไทม์จะเติมข้อมูลของผู้ใช้ ข้อมูลนี้ประกอบด้วยตัวระบุเฉพาะ ( uid ) ตลอดจนข้อมูลบัญชีที่เชื่อมโยง เช่น ID Facebook หรือที่อยู่อีเมล และข้อมูลอื่นๆ หากคุณใช้ผู้ให้บริการตรวจสอบสิทธิ์แบบกำหนดเอง คุณจะเพิ่มฟิลด์ของคุณเองลงในเพย์โหลดการตรวจสอบสิทธิ์ของผู้ใช้ได้

ส่วนนี้อธิบายวิธีรวมภาษากฎความปลอดภัยของฐานข้อมูลเรียลไทม์ของ Firebase กับข้อมูลการรับรองความถูกต้องเกี่ยวกับผู้ใช้ของคุณ ด้วยการรวมแนวคิดทั้งสองนี้เข้าด้วยกัน คุณจะสามารถควบคุมการเข้าถึงข้อมูลตามข้อมูลประจำตัวของผู้ใช้ได้

auth ความถูกต้อง

ตัวแปร auth ต้องที่กำหนดไว้ล่วงหน้าในกฎเป็นโมฆะก่อนที่จะมีการรับรองความถูกต้อง

เมื่อผู้ใช้ได้รับการรับรองความถูกต้องด้วย Firebase Authentication แล้ว จะมีแอตทริบิวต์ต่อไปนี้:

ผู้ให้บริการ วิธีการรับรองความถูกต้องที่ใช้ ("รหัสผ่าน", "ไม่ระบุตัวตน", "facebook", "github", "google" หรือ "twitter")
uid รหัสผู้ใช้ที่ไม่ซ้ำใคร รับประกันว่าจะไม่ซ้ำกันในทุกผู้ให้บริการ
โทเค็น เนื้อหาของโทเค็น Firebase Auth ID ดูเอกสารอ้างอิงสำหรับ auth.token สำหรับรายละเอียดเพิ่มเติม

นี่คือกฎตัวอย่างที่ใช้ตัวแปร auth เพื่อให้แน่ใจว่าผู้ใช้แต่ละรายสามารถเขียนไปยังเส้นทางเฉพาะของผู้ใช้เท่านั้น:

{
  "rules": {
    "users": {
      "$user_id": {
        // grants write access to the owner of this user account
        // whose uid must exactly match the key ($user_id)
        ".write": "$user_id === auth.uid"
      }
    }
  }
}

การจัดโครงสร้างฐานข้อมูลของคุณเพื่อรองรับเงื่อนไขการตรวจสอบสิทธิ์

โดยปกติจะเป็นประโยชน์ในการจัดโครงสร้างฐานข้อมูลของคุณในลักษณะที่ทำให้การเขียนกฎง่ายขึ้น รูปแบบหนึ่งทั่วไปสำหรับการจัดเก็บข้อมูลผู้ใช้ในฐานข้อมูลเรียลไทม์คือการจัดเก็บผู้ใช้ทั้งหมดของคุณในโหนด users เดียวซึ่งมีค่า uid ย่อยสำหรับผู้ใช้ทุกคน หากคุณต้องการจำกัดการเข้าถึงข้อมูลนี้เพื่อให้เฉพาะผู้ใช้ที่เข้าสู่ระบบเท่านั้นที่สามารถดูข้อมูลของตนเองได้ กฎของคุณจะมีลักษณะดังนี้

{
  "rules": {
    "users": {
      "$uid": {
        ".read": "auth !== null && auth.uid === $uid"
      }
    }
  }
}

การทำงานกับการอ้างสิทธิ์แบบกำหนดเองของการรับรองความถูกต้อง

สำหรับแอปที่ต้องการการควบคุมการเข้าถึงแบบกำหนดเองสำหรับผู้ใช้ที่แตกต่างกัน การรับรองความถูกต้องของ Firebase ช่วยให้นักพัฒนาสามารถ ตั้งค่าการอ้างสิทธิ์ในผู้ใช้ Firebase ได้ การอ้างสิทธิ์เหล่านี้สามารถเข้าถึงได้ในตัวแปร auth.token ในกฎของคุณ ต่อไปนี้คือตัวอย่างกฎที่ใช้การอ้างสิทธิ์ที่กำหนดเองของ hasEmergencyTowel :

{
  "rules": {
    "frood": {
      // A towel is about the most massively useful thing an interstellar
      // hitchhiker can have
      ".read": "auth.token.hasEmergencyTowel === true"
    }
  }
}

นักพัฒนาที่สร้าง โทเค็นการตรวจสอบสิทธิ์ที่กำหนดเอง สามารถเพิ่มการอ้างสิทธิ์ในโทเค็นเหล่านี้ได้ การอ้างสิทธิ์เหล่านี้มีอยู่ในตัวแปร auth.token ในกฎของคุณ

ข้อมูลที่มีอยู่กับข้อมูลใหม่

ตัวแปร data ที่กำหนดไว้ล่วงหน้าใช้เพื่ออ้างถึงข้อมูลก่อนที่จะดำเนินการเขียน ในทางกลับกัน ตัวแปร newData มีข้อมูลใหม่ที่จะเกิดขึ้นหากการดำเนินการเขียนสำเร็จ newData แสดงผลการผสานของข้อมูลใหม่ที่กำลังเขียนและข้อมูลที่มีอยู่

เพื่อแสดงให้เห็น กฎนี้จะอนุญาตให้เราสร้างบันทึกใหม่หรือลบบันทึกที่มีอยู่ แต่ไม่สามารถเปลี่ยนแปลงข้อมูลที่ไม่ใช่ค่าว่างที่มีอยู่ได้:

// we can write as long as old data or new data does not exist
// in other words, if this is a delete or a create, but not an update
".write": "!data.exists() || !newData.exists()"

การอ้างอิงข้อมูลในเส้นทางอื่น

สามารถใช้ข้อมูลใด ๆ เป็นเกณฑ์สำหรับกฎ การใช้ตัวแปรที่กำหนดไว้ล่วงหน้า root , data และ newData เราสามารถเข้าถึงพาธใดๆ ก็ได้ตามที่ควรจะเป็นก่อนหรือหลังเหตุการณ์การเขียน

ลองพิจารณาตัวอย่างนี้ ซึ่งอนุญาตการดำเนินการเขียนตราบเท่าที่ค่าของโหนด /allow_writes/ เป็น true โหนดพาเรนต์ไม่มีชุดแฟล็ก readOnly และมีลูกชื่อ foo ในข้อมูลที่เขียนใหม่:

".write": "root.child('allow_writes').val() === true &&
          !data.parent().child('readOnly').exists() &&
          newData.child('foo').exists()"

ตรวจสอบข้อมูล

การบังคับใช้โครงสร้างข้อมูลและการตรวจสอบความถูกต้องของรูปแบบและเนื้อหาของข้อมูลควรทำโดยใช้กฎ .validate ซึ่งจะทำงานหลังจากที่กฎ .write ให้สิทธิ์การเข้าถึงสำเร็จเท่านั้น ด้านล่างนี้เป็นตัวอย่างคำจำกัดความกฎ .validate ซึ่งอนุญาตเฉพาะวันที่ในรูปแบบ YYYY-MM-DD ระหว่างปี 1900-2099 ซึ่งตรวจสอบโดยใช้นิพจน์ทั่วไป

".validate": "newData.isString() &&
              newData.val().matches(/^(19|20)[0-9][0-9][-\\/. ](0[1-9]|1[012])[-\\/. ](0[1-9]|[12][0-9]|3[01])$/)"

กฎ .validate เป็นกฎความปลอดภัยประเภทเดียวที่ไม่เรียงลำดับ หากกฎการตรวจสอบใด ๆ ล้มเหลวในเรกคอร์ดลูก การดำเนินการเขียนทั้งหมดจะถูกปฏิเสธ นอกจากนี้ คำจำกัดความการตรวจสอบจะถูกละเว้นเมื่อข้อมูลถูกลบ (นั่นคือ เมื่อค่าใหม่ที่กำลังเขียนเป็น null )

สิ่งเหล่านี้อาจดูเหมือนเป็นประเด็นเล็กน้อย แต่อันที่จริงแล้วเป็นคุณสมบัติที่สำคัญสำหรับการเขียนกฎความปลอดภัยของฐานข้อมูลเรียลไทม์ของ Firebase ที่ทรงพลัง พิจารณากฎต่อไปนี้:

{
  "rules": {
    // write is allowed for all paths
    ".write": true,
    "widget": {
      // a valid widget must have attributes "color" and "size"
      // allows deleting widgets (since .validate is not applied to delete rules)
      ".validate": "newData.hasChildren(['color', 'size'])",
      "size": {
        // the value of "size" must be a number between 0 and 99
        ".validate": "newData.isNumber() &&
                      newData.val() >= 0 &&
                      newData.val() <= 99"
      },
      "color": {
        // the value of "color" must exist as a key in our mythical
        // /valid_colors/ index
        ".validate": "root.child('valid_colors/' + newData.val()).exists()"
      }
    }
  }
}

เมื่อคำนึงถึงตัวแปรนี้แล้ว ให้ดูที่ผลลัพธ์สำหรับการดำเนินการเขียนต่อไปนี้:

จาวาสคริปต์
var ref = db.ref("/widget");

// PERMISSION_DENIED: does not have children color and size
ref.set('foo');

// PERMISSION DENIED: does not have child color
ref.set({size: 22});

// PERMISSION_DENIED: size is not a number
ref.set({ size: 'foo', color: 'red' });

// SUCCESS (assuming 'blue' appears in our colors list)
ref.set({ size: 21, color: 'blue'});

// If the record already exists and has a color, this will
// succeed, otherwise it will fail since newData.hasChildren(['color', 'size'])
// will fail to validate
ref.child('size').set(99);
วัตถุประสงค์-C
หมายเหตุ: ผลิตภัณฑ์ Firebase นี้ไม่มีอยู่ในเป้าหมาย App Clip
FIRDatabaseReference *ref = [[[FIRDatabase database] reference] child: @"widget"];

// PERMISSION_DENIED: does not have children color and size
[ref setValue: @"foo"];

// PERMISSION DENIED: does not have child color
[ref setValue: @{ @"size": @"foo" }];

// PERMISSION_DENIED: size is not a number
[ref setValue: @{ @"size": @"foo", @"color": @"red" }];

// SUCCESS (assuming 'blue' appears in our colors list)
[ref setValue: @{ @"size": @21, @"color": @"blue" }];

// If the record already exists and has a color, this will
// succeed, otherwise it will fail since newData.hasChildren(['color', 'size'])
// will fail to validate
[[ref child:@"size"] setValue: @99];
สวิฟต์
หมายเหตุ: ผลิตภัณฑ์ Firebase นี้ไม่มีอยู่ในเป้าหมาย App Clip
var ref = FIRDatabase.database().reference().child("widget")

// PERMISSION_DENIED: does not have children color and size
ref.setValue("foo")

// PERMISSION DENIED: does not have child color
ref.setValue(["size": "foo"])

// PERMISSION_DENIED: size is not a number
ref.setValue(["size": "foo", "color": "red"])

// SUCCESS (assuming 'blue' appears in our colors list)
ref.setValue(["size": 21, "color": "blue"])

// If the record already exists and has a color, this will
// succeed, otherwise it will fail since newData.hasChildren(['color', 'size'])
// will fail to validate
ref.child("size").setValue(99);
ชวา
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference ref = database.getReference("widget");

// PERMISSION_DENIED: does not have children color and size
ref.setValue("foo");

// PERMISSION DENIED: does not have child color
ref.child("size").setValue(22);

// PERMISSION_DENIED: size is not a number
Map<String,Object> map = new HashMap<String, Object>();
map.put("size","foo");
map.put("color","red");
ref.setValue(map);

// SUCCESS (assuming 'blue' appears in our colors list)
map = new HashMap<String, Object>();
map.put("size", 21);
map.put("color","blue");
ref.setValue(map);

// If the record already exists and has a color, this will
// succeed, otherwise it will fail since newData.hasChildren(['color', 'size'])
// will fail to validate
ref.child("size").setValue(99);
พักผ่อน
# PERMISSION_DENIED: does not have children color and size
curl -X PUT -d 'foo' \
https://docs-examples.firebaseio.com/rest/securing-data/example.json

# PERMISSION DENIED: does not have child color
curl -X PUT -d '{"size": 22}' \
https://docs-examples.firebaseio.com/rest/securing-data/example.json

# PERMISSION_DENIED: size is not a number
curl -X PUT -d '{"size": "foo", "color": "red"}' \
https://docs-examples.firebaseio.com/rest/securing-data/example.json

# SUCCESS (assuming 'blue' appears in our colors list)
curl -X PUT -d '{"size": 21, "color": "blue"}' \
https://docs-examples.firebaseio.com/rest/securing-data/example.json

# If the record already exists and has a color, this will
# succeed, otherwise it will fail since newData.hasChildren(['color', 'size'])
# will fail to validate
curl -X PUT -d '99' \
https://docs-examples.firebaseio.com/rest/securing-data/example/size.json

ทีนี้มาดูโครงสร้างเดียวกัน แต่ใช้กฎ .write แทน .validate :

{
  "rules": {
    // this variant will NOT allow deleting records (since .write would be disallowed)
    "widget": {
      // a widget must have 'color' and 'size' in order to be written to this path
      ".write": "newData.hasChildren(['color', 'size'])",
      "size": {
        // the value of "size" must be a number between 0 and 99, ONLY IF WE WRITE DIRECTLY TO SIZE
        ".write": "newData.isNumber() && newData.val() >= 0 && newData.val() <= 99"
      },
      "color": {
        // the value of "color" must exist as a key in our mythical valid_colors/ index
        // BUT ONLY IF WE WRITE DIRECTLY TO COLOR
        ".write": "root.child('valid_colors/'+newData.val()).exists()"
      }
    }
  }
}

ในรูปแบบนี้ การดำเนินการใดๆ ต่อไปนี้จะสำเร็จ:

จาวาสคริปต์
var ref = new Firebase(URL + "/widget");

// ALLOWED? Even though size is invalid, widget has children color and size,
// so write is allowed and the .write rule under color is ignored
ref.set({size: 99999, color: 'red'});

// ALLOWED? Works even if widget does not exist, allowing us to create a widget
// which is invalid and does not have a valid color.
// (allowed by the write rule under "color")
ref.child('size').set(99);
วัตถุประสงค์-C
หมายเหตุ: ผลิตภัณฑ์ Firebase นี้ไม่มีอยู่ในเป้าหมาย App Clip
Firebase *ref = [[Firebase alloc] initWithUrl:URL];

// ALLOWED? Even though size is invalid, widget has children color and size,
// so write is allowed and the .write rule under color is ignored
[ref setValue: @{ @"size": @9999, @"color": @"red" }];

// ALLOWED? Works even if widget does not exist, allowing us to create a widget
// which is invalid and does not have a valid color.
// (allowed by the write rule under "color")
[[ref childByAppendingPath:@"size"] setValue: @99];
สวิฟต์
หมายเหตุ: ผลิตภัณฑ์ Firebase นี้ไม่มีอยู่ในเป้าหมาย App Clip
var ref = Firebase(url:URL)

// ALLOWED? Even though size is invalid, widget has children color and size,
// so write is allowed and the .write rule under color is ignored
ref.setValue(["size": 9999, "color": "red"])

// ALLOWED? Works even if widget does not exist, allowing us to create a widget
// which is invalid and does not have a valid color.
// (allowed by the write rule under "color")
ref.childByAppendingPath("size").setValue(99)
ชวา
Firebase ref = new Firebase(URL + "/widget");

// ALLOWED? Even though size is invalid, widget has children color and size,
// so write is allowed and the .write rule under color is ignored
Map<String,Object> map = new HashMap<String, Object>();
map.put("size", 99999);
map.put("color", "red");
ref.setValue(map);

// ALLOWED? Works even if widget does not exist, allowing us to create a widget
// which is invalid and does not have a valid color.
// (allowed by the write rule under "color")
ref.child("size").setValue(99);
พักผ่อน
# ALLOWED? Even though size is invalid, widget has children color and size,
# so write is allowed and the .write rule under color is ignored
curl -X PUT -d '{size: 99999, color: "red"}' \
https://docs-examples.firebaseio.com/rest/securing-data/example.json

# ALLOWED? Works even if widget does not exist, allowing us to create a widget
# which is invalid and does not have a valid color.
# (allowed by the write rule under "color")
curl -X PUT -d '99' \
https://docs-examples.firebaseio.com/rest/securing-data/example/size.json

สิ่งนี้แสดงให้เห็นถึงความแตกต่างระหว่างกฎ .write และ .validate ตามที่แสดงให้เห็น กฎเหล่านี้ทั้งหมดควรเขียนโดยใช้ .validate โดยมีข้อยกเว้นที่เป็นไปได้ของกฎ newData.hasChildren() ซึ่งจะขึ้นอยู่กับว่าควรอนุญาตให้ลบหรือไม่

กฎตามแบบสอบถาม

แม้ว่าคุณ จะไม่สามารถใช้กฎเป็นตัวกรอง แต่คุณก็สามารถจำกัดการเข้าถึงข้อมูลชุดย่อยได้โดยใช้พารามิเตอร์การค้นหาในกฎของคุณ ใช้ query. นิพจน์ในกฎของคุณเพื่อให้สิทธิ์การเข้าถึงแบบอ่านหรือเขียนตามพารามิเตอร์การค้นหา

ตัวอย่างเช่น กฎตามคิวรีต่อไปนี้ใช้ กฎความปลอดภัยตามผู้ใช้ และกฎตามคิวรีเพื่อจำกัดการเข้าถึงข้อมูลในคอลเล็กชัน baskets ให้เฉพาะตะกร้าสินค้าที่ผู้ใช้ที่ใช้งานอยู่เป็นเจ้าของเท่านั้น:

"baskets": {
  ".read": "auth.uid !== null &&
            query.orderByChild === 'owner' &&
            query.equalTo === auth.uid" // restrict basket access to owner of basket
}

ข้อความค้นหาต่อไปนี้ซึ่งมีพารามิเตอร์ข้อความค้นหาในกฎจะสำเร็จ:

db.ref("baskets").orderByChild("owner")
                 .equalTo(auth.currentUser.uid)
                 .on("value", cb)                 // Would succeed

อย่างไรก็ตาม ข้อความค้นหาที่ไม่มีพารามิเตอร์ในกฎจะล้มเหลวโดยมีข้อผิดพลาด PermissionDenied :

db.ref("baskets").on("value", cb)                 // Would fail with PermissionDenied

คุณยังสามารถใช้กฎตามคิวรีเพื่อจำกัดจำนวนข้อมูลที่ไคลเอนต์ดาวน์โหลดผ่านการดำเนินการอ่าน

ตัวอย่างเช่น กฎต่อไปนี้จำกัดการเข้าถึงการอ่านเฉพาะผลลัพธ์ 1,000 รายการแรกของข้อความค้นหา โดยเรียงลำดับตามลำดับความสำคัญ:

messages: {
  ".read": "query.orderByKey &&
            query.limitToFirst <= 1000"
}

// Example queries:

db.ref("messages").on("value", cb)                // Would fail with PermissionDenied

db.ref("messages").limitToFirst(1000)
                  .on("value", cb)                // Would succeed (default order by key)

query. ต่อไปนี้ นิพจน์มีอยู่ในกฎความปลอดภัยของฐานข้อมูลแบบเรียลไทม์

นิพจน์กฎตามแบบสอบถาม
การแสดงออก พิมพ์ คำอธิบาย
แบบสอบถาม orderByKey
แบบสอบถาม orderByPriority
แบบสอบถาม orderByValue
บูลีน เป็นจริงสำหรับข้อความค้นหาที่เรียงลำดับตามคีย์ ลำดับความสำคัญ หรือค่า เป็นอย่างอื่น
สอบถาม.orderByChild สตริง
โมฆะ
ใช้สตริงเพื่อแสดงเส้นทางสัมพัทธ์ไปยังโหนดย่อย ตัวอย่างเช่น query.orderByChild === "address/zip" หากคิวรีไม่ได้เรียงลำดับตามโหนดย่อย ค่านี้จะเป็นค่าว่าง
แบบสอบถาม.startAt
แบบสอบถามสิ้นสุดที่
แบบสอบถามเท่ากับ
สตริง
ตัวเลข
บูลีน
โมฆะ
ดึงขอบเขตของแบบสอบถามที่กำลังดำเนินการ หรือคืนค่า null หากไม่มีชุดขอบเขต
แบบสอบถาม.limitToFirst
แบบสอบถาม.limitToLast
ตัวเลข
โมฆะ
ดึงค่าขีดจำกัดของคิวรีที่กำลังดำเนินการ หรือคืนค่า null หากไม่มีการตั้งค่าขีดจำกัด

ขั้นตอนถัดไป

หลังจากการอภิปรายเกี่ยวกับเงื่อนไขนี้ คุณมีความเข้าใจกฎที่ซับซ้อนมากขึ้น และพร้อมที่จะ:

เรียนรู้วิธีจัดการกับกรณีการใช้งานหลัก และเรียนรู้เวิร์กโฟลว์สำหรับการพัฒนา ทดสอบ และปรับใช้กฎ:

เรียนรู้กฎคุณสมบัติเฉพาะสำหรับฐานข้อมูลเรียลไทม์: