React-native-firebase: Firestore: Query with a field reference

Created on 10 Nov 2017  路  6Comments  路  Source: invertase/react-native-firebase

Issue

I'm attempting to query a collection in which the documents have a field that is a reference. Each document contains an owner field, which is a referenceValue type.

My initial attempt was to query like this:

const ref = firebase.firestore().collection('users').doc('my-user-id') firebase.firestore().collection('docs').where('owner', '==', ref)

I got some weird errors (below), so I decided to use the node.js lib (firebase-admin) to run the exact same command. This was successful, which leads me to believe this issue may be in the react-native-firebase lib, not upstream (but would be happy to be corrected!).

This throws when _executing_ the query (via get or onSnapshot), not when constructing.

The firebase-admin code that works is as follows:

const firebase = require('firebase-admin')
firebase.initializeApp({
  credential: firebase.credential.cert(<snip>),
  databaseURL: '<snip>'
});
const db = firebase.firestore()
const uid = '<snip>'
const userRef = db.collection('users').doc(uid)
db
  .collection('docs')
  .where('owner', '==', userRef)
  .get()
  .then(r => {
    r.forEach(n => console.log(n))
  })

I _believe_ this issue is the same thing #585 was having a problem with, but it's unclear so I made a new issue.

Here is the error:

Malformed calls from JS: field sizes are different.

[[46,46,46,46,46,46,46,46,46,46,46,46,1,1,29,29,1,46,46,46,46,46,46,46,46,46,46,46,46,29],[6,6,6,6,6,6,6,6,6,6,6,6,8,0,0,1,9,6,6,6,6,6,6,6,6,6,6,6,6,0],[[2,"RCTImageView",null],[3,"RCTImageView",null],[5,"RCTText",null],[6,"RCTActivityIndicatorView",null],[7,"RCTView",null],[8,"RCTView",null],[9,"RCTView",null],[10,"RCTView",null],[12,"RCTView",null],[13,"RCTView",null],[14,"RCTView",null],[15,"RCTView",null],["__FIRAPP_DEFAULT","users/hKuTsmkUqXOzQ10qPbIaomqmeWn1","Ep9RNK39WRKqEqjc0463",{}],[7,100,1510280745744,false],[7],["__FIRAPP_DEFAULT","users/hKuTsmkUqXOzQ10qPbIaomqmeWn1",{"displayName":{"value":null,"type":"null"},"phoneNumber":{"value":null,"type":"null"},"providerData":{"value":[{"type":"object","value":{"phoneNumber":{"type":"string","value":"+14156567383"},"providerId":{"type":"string","value":"phone"}}}],"type":"array"},"refreshToken":{"value":<snip>,"type":"string"},"providerId":{"value":"firebase","type":"string"},"uid":{"value":"hKuTsmkUqXOzQ10qPbIaomqmeWn1","type":"string"},"emailVerified":{"value":false,"type":"boolean"},"email":{"value":null,"type":"null"},"isAnonymous":{"value":false,"type":"boolean"}},{"merge":true},138,139],[2,"RCTImageView",null],[3,"RCTImageView",null],[5,"RCTText",null],[6,"RCTActivityIndicatorView",null],[7,"RCTView",null],[8,"RCTView",null],[9,"RCTView",null],[10,"RCTView",null],[12,"RCTView",null],[13,"RCTView",null],[14,"RCTView",null],[15,"RCTView",null],[10,100,1510280745754,false]],53]

Environment

  1. Application Target Platform: iOS
  2. Development Operating System: macOS Sierra
  3. Build Tools: XCode, but likely irrelevant
  4. React Native version: 0.49.5
  5. RNFirebase Version: 3.0.6
  6. Firebase Module: firestore

Most helpful comment

@jesseditson I wouldn't call this noise. It provided useful documentation on how to use a reference for querying. I didn't find that anywhere in the documentation.

Thanks for contributing!

All 6 comments

Ah, looks like this is perhaps fixed here: https://github.com/invertase/react-native-firebase/commit/6ae004933867ffc8bb40fbe584ee49ed3c90d61b - I'll update to v3.1.0 and try again...

Fix verified! Sorry for the noise!

@jesseditson I wouldn't call this noise. It provided useful documentation on how to use a reference for querying. I didn't find that anywhere in the documentation.

Thanks for contributing!

@ralphsmith80 we generally don't go into extensive detail on the docs as when we implement functionality/methods in RNF they're to the same specification as the official Firebase Web SDK which Google have documented extensively on the Firebase website.

The aim is that our docs are more of a brief overview of what we support and whats different to the official SDK's and that the official Firebase docs match up to what we've implemented.

An example of the official docs showing usage just like the above: https://firebase.google.com/docs/firestore/query-data/query-cursors#use_a_document_snapshot_to_define_the_query_cursor

There are still places though where our docs can be improved and we welcome PR's to speed along the process 馃憤

@jesseditson Can you please confirm if this is really working? I have same scenario where I need to add where condition with reference to other collection document. Please update here with latest working query.

const ref = firebase.firestore().collection('users').doc('my-user-id')
firebase.firestore().collection('docs').where('owner', '==', ref)

Hi @avinashyalgonde! This issue is two years old and probably not the best place to get help troubleshooting. Stackoverflow is an excellent place to ask questions like this!

Was this page helpful?
0 / 5 - 0 ratings