How can I set a Reference field in Firestore Document (NodeJS)

8,257 views
Skip to first unread message

Ray

unread,
Oct 4, 2017, 9:58:28 AM10/4/17
to Firebase Google Group
I am trying to set a DocumentReference in a doc from NodeJS(Admin SDK) - like this

const ref = db.doc('foo/someDoc')
await db.doc('bar/newDoc').set({ foo: ref })

 However, it results
 
Error: Argument "data" is not a valid Document. Input object is deeper than 20 levels or contains a cycle.


 Since it's possible on console, I bet there's a way to do it with the sdk, but I can't figure out how. Any idea or document?

David Negstad

unread,
Oct 5, 2017, 7:18:55 PM10/5/17
to Firebase Google Group
Looks like there's a _referencePath property on document references you can use.

const ref = db.doc('foo/someDoc')
await db.doc('bar/newDoc').set({ foo: ref._referencePath })

Sebastian Schmidt

unread,
Oct 5, 2017, 9:07:28 PM10/5/17
to Firebase Google Group
Hello,
this is an issue in the interactions between the Firestore Node SDK and the Firestore Admin SDK. If you are able to use the Node SDK ("@google-cloud/firestore") directly, then you should be able to save a DocumentReference.

We have committed a fix for this issue (https://github.com/googleapis/nodejs-firestore/pull/29) and are working on a release. I will inform this group when this release is ready.

Thanks,
Sebastian

Sebastian Schmidt

unread,
Oct 10, 2017, 11:15:35 PM10/10/17
to Firebase Google Group
Hello,
just to circle back on this - this has been fixed in the Firestore library. You can pull this in by updating the Admin SDK.

- Sebastian
Reply all
Reply to author
Forward
0 new messages