appwrite / sdk-for-node

[READ-ONLY] Official Appwrite Node.js SDK 🟒

Home Page:https://appwrite.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸš€ Feature: add new function called findDocument() to find a document by query

bill-zhanxg opened this issue Β· comments

πŸ”– Feature description

Add a new function in the Database SDK called findDocument which uses listDocument to get the first returned document with Query.

🎀 Pitch

This feature can be used if you have an id for attitude such as a user_id attribute and don't want it to be the same as the document id.

πŸ‘€ Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏒 Have you read the Code of Conduct?

maybe something like

     /**
     * List Documents
     * Get the first user's documents in a given collection using queries to filter your results.
     * @param databaseId
     * @param collectionId
     * @param queries
     * @throws β€” {AppwriteException}
     */
	findDocument<Document extends Models.Document>(
		databaseId: string,
		collectionId: string,
		queries: string[],
	): Promise<Document> {
		return new Promise((resolve, reject) => {
			this.listDocuments(databaseId, collectionId, queries)
				.then((document) => {
					if (document.documents[0]) resolve(document.documents[0]);
					else throw new AppwriteException('No document found');
				})
				.catch(reject);
		});
	}

Hi
As I can understand from this, you are looking to find a particular document in the list of documents. Currently, you can do this using loops and if you prefer changing the search parameters, you can use queries for you to filter, sort, and paginate results.

I will keep this issue open as of now since we are very keen in considering feedbacks from our community