ब्यौरा
यह फ़ंक्शन, किसी कलेक्शन में मौजूद सभी दस्तावेज़ों को दिखाता है. कलेक्शन को नेस्ट किया जा सकता है.
सिंटैक्स
Node.js
const results = await db.pipeline()
.collection('/cities/SF/departments')
.execute();
क्लाइंट के उदाहरण
Web
const results = await execute(db.pipeline() .collection("users/bob/games") .sort(field("name").ascending()) );
Swift
let results = try await db.pipeline() .collection("users/bob/games") .sort([Field("name").ascending()]) .execute()
Kotlin
val results = db.pipeline() .collection("users/bob/games") .sort(field("name").ascending()) .execute()
Java
Task<Pipeline.Snapshot> results = db.pipeline() .collection("users/bob/games") .sort(field("name").ascending()) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field results = ( client.pipeline() .collection("users/bob/games") .sort(Field.of("name").ascending()) .execute() )
Java
Pipeline.Snapshot results = firestore .pipeline() .collection("users/bob/games") .sort(ascending(field("name"))) .execute() .get();
व्यवहार
collection स्टेज का इस्तेमाल करने के लिए, यह ज़रूरी है कि यह पाइपलाइन में पहली स्टेज के तौर पर दिखे.
collection स्टेज से मिले दस्तावेज़ों का क्रम बदलता रहता है. इसलिए, इस पर भरोसा नहीं करना चाहिए. डेटा को क्रम से लगाने के लिए, बाद में सॉर्टिंग स्टेज का इस्तेमाल किया जा सकता है.
उदाहरण के लिए, इन दस्तावेज़ों के लिए:
Node.js
await db.collection('cities').doc('SF').set({name: 'San Francsico', state: 'California'});
await db.collection('cities').doc('NYC').set({name: 'New York City', state: 'New York'});
await db.collection('cities').doc('CHI').set({name: 'Chicago', state: 'Illinois'});
await db.collection('states').doc('CA').set({name: 'California'});
collection स्टेज का इस्तेमाल, cities कलेक्शन में मौजूद सभी शहरों को वापस पाने के लिए किया जा सकता है. इसके बाद, उन्हें नाम के हिसाब से बढ़ते क्रम में लगाया जा सकता है.
Node.js
const results = await db.pipeline()
.collection('/cities')
.sort(field('name').ascending())
.execute();
इस क्वेरी से ये दस्तावेज़ मिलते हैं:
{name: 'Chicago', state: 'Illinois'}
{name: 'New York City', state: 'New York'}
{name: 'San Francisco', state: 'California'}
सब-कलेक्शन
collection स्टेज का इस्तेमाल, किसी खास पैरंट के तहत मौजूद कलेक्शन को टारगेट करने के लिए भी किया जा सकता है. इसके लिए, स्टेज का पूरा पाथ देना होगा.
उदाहरण के लिए, इन दस्तावेज़ों के लिए:
Node.js
await db.collection('cities/SF/departments').doc('building').set({name: 'SF Building Deparment', employees: 750});
await db.collection('cities/NY/departments').doc('building').set({name: 'NY Building Deparment', employees: 1000});
await db.collection('cities/CHI/departments').doc('building').set({name: 'CHI Building Deparment', employees: 900});
await db.collection('cities/NY/departments').doc('finance').set({name: 'NY Finance Deparment', employees: 1200});
इस उदाहरण के लिए, हमें सिर्फ़ न्यूयॉर्क शहर के डिपार्टमेंट चाहिए.
Node.js
const results = await db.pipeline()
.collection('/cities/NY/departments')
.sort(field('employees').ascending())
.execute();
इससे, पूरे पाथ cities/NY/departments के तहत आने वाले सभी डिपार्टमेंट दिखेंगे.
{name: 'NY Building Deparment', employees: 1000}
{name: 'NY Finance Deparment', employees: 1200}