2

I am trying to create collections and sub collections for document inside a collection dynamically from cloud functions, But I am getting following exception **

Argument "collectionPath" must point to a collection, but was "data/c2f7c4e84366". Your path does not contain an odd number of components

**

Logs -

Error: Argument "documentPath" must point to a document, but was "exports/user343434_inbox/profile". Your path does not contain an even number of components. at Firestore.doc (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/index.js:282:13) at admin.firestore.doc.set.then.ws (/user_code/lib/index.js:28:53)

code snippet: const p = admin.firestore().doc(exports/${userInboxCollectionName}/profile).set(reqData, { merge: false }) *

I am expecting cloud function to create the subcollection(userid_inbox) inside exports collection(already exists) dynamically if not exists and add the profile document.

1
  • 3
    Please edit your question to show the code that generates this error. Commented Jun 15, 2018 at 6:36

1 Answer 1

1

Firestore works like this: collection / document / subCollection / "subDocument" / and so on.

You should try: (I'm using TS)

let p = admin.firestore().collection(`exports/${userUID}/${theSubcollection}`)
    .add({ message: messageString })
    .then(ref => {
        console.log('Added document with ID: ', ref.id)
});

//let's see the estructure here:
//collection.......exports   
//document.........${userUID}
//subcollection....${theSubcollection}
//document.........ref.id
//data.............message with value messageString

with this code you are creating an new document with the value message on a new subcollection.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.