Firebase collection method doesn't return CollectionReference object

Viewed 178

This is my first time using StackOverflow. Hope someone can help me out!

I am trying to write React-redux application and currently trying to integrate Firebase into the application. When I console.log a collectionReference object, the object name is called n for some reason, and the keys of the object seems to be gibberish, such as Ch, Hw, etc... I am not sure what is going on. Does anyone know console.log doesn't seem to give me information on my collection object? Is it because the data is somehow encrypted for security reasons? This is the method I wrote for concole.loging a collectionReference object.

export const addCollectionAndDocuments = (collectionKeys, objectsToAdd) => {
  const collectionRef = firestore.collection(collectionKeys);
  console.log(collectionRef);
};

This is the response I get.

n {qa: t, Hd: t, dw: t, firestore: t, Qa: null, …}
Cw: n {segments: Array(1), offset: 0, m: 1}
Hd: t {s: t, ignoreUndefinedProperties: false, serializer: Ft}
Qa: null
dw: t {path: n, collectionGroup: null, ds: Array(0), filters: Array(0), limit: null, …}
firestore: t {Bd: FirebaseAppImpl, qd: t, INTERNAL: {…}, qa: t, jd: "[DEFAULT]", …}
id: (...)
parent: (...)
path: (...)
qa: t {projectId: "shop-2b337", database: "(default)"}
__proto__: n
2 Answers

Those Ch, hW, etc. look like minified internal properties, they're just private stuff you won't need (hence why they're not human-readable). You will not see your data enumerated on a CollectionReference, or even have access to any data directly yet, because you haven't asked for anything, only selected a collection.

Like @Chris said, use .doc() to select a document or make queries with .get(), .where and other methods to actually get data. I recommend following along the Firebase docs as you set up your app.

I'm not sure what you're expecting the console log to print out, but Christian is right, you're looking at a mangled internal representation of a CollectionReference object. It doesn't have a meaningful string format.

If you want to log something meaningful, perhaps you could use path or one of its other documented properties. If you need document data from that collection, you'll have to make a query with it.

Related