0

Is it possible to omit particular fields when performing a Firebase query?

The following query:

 getReferredUsers(referralId) {
    this.logger.debug(`Getting referred users by referral id ${referralId}`);
    if (referralId) {
      return this.afs.collection('users', ref => ref.where('referredBy', '==', referralId).limit(3)).valueChanges();
    }
  }

Returns the following:

  {
    "displayName": null,
    "email": "theshizy@hotmail.co.uk",
    "emailVerified": true,
    "firstName": "James",
    "lastName": "Burton",
    "photoURL": "https://i.imgur.com/LHhAQBH.jpg",
    "referralId": "6O5qGmRQ",
    "referredBy": "cpRcYiov",
    "selectedCurrency": "GBP",
    "selectedTimezone": "(UTC) Edinburgh, London",
    "uid": "LjZ8TAb4ZGhgw2DGubbVosw8dkd2"
  }
]

Can I cut it down further so that it only returns the following:

  {
    "emailVerified": true,
    "firstName": "James",
    "lastName": "Burton",
    "photoURL": "https://i.imgur.com/LHhAQBH.jpg",
    "referralId": "6O5qGmRQ",
  }
]
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
methuselah
  • 12,766
  • 47
  • 165
  • 315

1 Answers1

0

The Firestore client-side SDKs always returns complete documents. There is no way to request only a part of the document with the client-side SDK, although the option does exist in the server-side SDKs' select methods.

If you only need a part of the information, consider creating an additional collection where each document just contains the data you need. This will also allow you to more easily secure access to the different types of data.

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807