"Expected Ref and got Object" when attempting to start stream using Ref

I’m attempting to setup streaming on an application and running into an error, here’s my code sample:

    let { Collection, Ref } = faunadb.query;
    let docRef = Ref(Collection('groups', id));
      .on('snapshot', (snapshot) => {
        console.log('Snapshot came in:', snapshot);
      .on('version', (version) => {
        console.log('version came in:', version);
      .on('error', (error) => {
        console.log('Error:', error);

But I’m getting the following error:
code “invalid expression”
description “Ref expected, Object provided.”

As far as I can tell, that’s the correct way to get a ref? And the ref in question exists, and the payload that is sent from the JS client seems right


Hi @rjfranco! There is a typo here

That is, it should be:

let docRef = Ref(Collection('groups'), id);

The error comes up like this, because Collection does accept a second argument: A database Ref. The typo above passes in a string, which is not a database Ref, and so the query fails.

Omg thank you, this is what happens when you’re coding too late :joy:


Lol. Yep I get that :relaxed:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.