A VectorQuerySnapshot
contains zero or more QueryDocumentSnapshot
objects representing the results of a query. The documents can be accessed as an array via the docs
property or enumerated using the forEach
method. The number of documents can be determined via the empty
and size
properties.
Package
@google-cloud/firestoreRemarks
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the VectorQuerySnapshot
class.
Properties
docs
get docs(): Array<QueryDocumentSnapshot<AppModelType, DbModelType>>;
An array of all the documents in this VectorQuerySnapshot
.
let query = firestore.collection('col')
.findNearest("embedding", [0, 0], {limit: 10, distanceMeasure: "EUCLIDEAN"});
query.get().then(querySnapshot => {
let docs = querySnapshot.docs;
for (let doc of docs) {
console.log(`Document found at path: ${doc.ref.path}`);
}
});
empty
get empty(): boolean;
true
if there are no documents in the VectorQuerySnapshot
.
let query = firestore.collection('col')
.findNearest("embedding", [0, 0], {limit: 10, distanceMeasure: "EUCLIDEAN"});
query.get().then(querySnapshot => {
if (querySnapshot.empty) {
console.log('No documents found.');
}
});
query
get query(): VectorQuery<AppModelType, DbModelType>;
The VectorQuery
on which you called get() in order to get this VectorQuerySnapshot
.
let query = firestore.collection('col').where('foo', '==', 'bar');
query.findNearest("embedding", [0, 0], {limit: 10, distanceMeasure: "EUCLIDEAN"})
.get().then(querySnapshot => {
console.log(`Returned first batch of results`);
let query = querySnapshot.query;
return query.offset(10).get();
}).then(() => {
console.log(`Returned second batch of results`);
});
readTime
get readTime(): Timestamp;
The time this VectorQuerySnapshot
was obtained.
let query = firestore.collection('col')
.findNearest("embedding", [0, 0], {limit: 10, distanceMeasure: "EUCLIDEAN"});
query.get().then((querySnapshot) => {
let readTime = querySnapshot.readTime;
console.log(`Query results returned at '${readTime.toDate()}'`);
});
size
get size(): number;
The number of documents in the VectorQuerySnapshot
.
let query = firestore.collection('col')
.findNearest("embedding", [0, 0], {limit: 10, distanceMeasure: "EUCLIDEAN"});
query.get().then(querySnapshot => {
console.log(`Found ${querySnapshot.size} documents.`);
});
Methods
docChanges()
docChanges(): Array<DocumentChange<AppModelType, DbModelType>>;
Returns an array of the documents changes since the last snapshot. If this is the first snapshot, all documents will be in the list as added changes.
Returns | |
---|---|
Type | Description |
Array<DocumentChange<AppModelType, DbModelType>> |
An array of the documents changes since the last snapshot. |
let query = firestore.collection('col')
.findNearest("embedding", [0, 0], {limit: 10, distanceMeasure: "EUCLIDEAN"});
query.get().then(querySnapshot => {
let changes = querySnapshot.docChanges();
for (let change of changes) {
console.log(`A document was ${change.type}.`);
}
});
forEach(callback, thisArg)
forEach(callback: (result: firestore.QueryDocumentSnapshot<AppModelType, DbModelType>) => void, thisArg?: unknown): void;
Enumerates all of the documents in the VectorQuerySnapshot
. This is a convenience method for running the same callback on each QueryDocumentSnapshot that is returned.
Parameters | |
---|---|
Name | Description |
callback |
(result: FirebaseFirestore.QueryDocumentSnapshot<AppModelType, DbModelType>) => void
A callback to be called with a QueryDocumentSnapshot for each document in the snapshot. |
thisArg |
unknown
The |
Returns | |
---|---|
Type | Description |
void |
let query = firestore.collection('col')
.findNearest("embedding", [0, 0], {limit: 10, distanceMeasure: "EUCLIDEAN"});
query.get().then(querySnapshot => {
querySnapshot.forEach(documentSnapshot => {
console.log(`Document found at path: ${documentSnapshot.ref.path}`);
});
});
isEqual(other)
isEqual(other: firestore.VectorQuerySnapshot<AppModelType, DbModelType>): boolean;
Returns true if the document data in this VectorQuerySnapshot
is equal to the provided value.
Parameter | |
---|---|
Name | Description |
other |
FirebaseFirestore.VectorQuerySnapshot<AppModelType, DbModelType>
The value to compare against. |
Returns | |
---|---|
Type | Description |
boolean |
true if this |