Is there a way to copy doc value into another one without pulling the data and sending back










0















I have 2 docs posts and postDrafts. In some point I want to publish the document from the postDraft into post.
The content is something like body: "blah blah".



So the trivial solution is to pull the postDraft content and then send back to posts document. Here is my code for that.



 export const publishDraftById = (postId) => async dispatch => 
return new Promise((resolve, reject) =>
postDraftsRef.doc(postId).get()
.then(doc =>
if (!doc.exists)
reject('No such document!');
else
const draft = doc.data();
postsRef.doc(postId).update(
body: draft.body,
date_modified: new Date()
);
resolve();

)
.catch((err) =>
reject(err);
console.log('Error getting documents', err);
);
)
;


But what I really think can be helpful is a way to do something like this meta code



"assign posts(postid).body = postDraft(postid).body"



Can I somehow approach this?










share|improve this question




























    0















    I have 2 docs posts and postDrafts. In some point I want to publish the document from the postDraft into post.
    The content is something like body: "blah blah".



    So the trivial solution is to pull the postDraft content and then send back to posts document. Here is my code for that.



     export const publishDraftById = (postId) => async dispatch => 
    return new Promise((resolve, reject) =>
    postDraftsRef.doc(postId).get()
    .then(doc =>
    if (!doc.exists)
    reject('No such document!');
    else
    const draft = doc.data();
    postsRef.doc(postId).update(
    body: draft.body,
    date_modified: new Date()
    );
    resolve();

    )
    .catch((err) =>
    reject(err);
    console.log('Error getting documents', err);
    );
    )
    ;


    But what I really think can be helpful is a way to do something like this meta code



    "assign posts(postid).body = postDraft(postid).body"



    Can I somehow approach this?










    share|improve this question


























      0












      0








      0








      I have 2 docs posts and postDrafts. In some point I want to publish the document from the postDraft into post.
      The content is something like body: "blah blah".



      So the trivial solution is to pull the postDraft content and then send back to posts document. Here is my code for that.



       export const publishDraftById = (postId) => async dispatch => 
      return new Promise((resolve, reject) =>
      postDraftsRef.doc(postId).get()
      .then(doc =>
      if (!doc.exists)
      reject('No such document!');
      else
      const draft = doc.data();
      postsRef.doc(postId).update(
      body: draft.body,
      date_modified: new Date()
      );
      resolve();

      )
      .catch((err) =>
      reject(err);
      console.log('Error getting documents', err);
      );
      )
      ;


      But what I really think can be helpful is a way to do something like this meta code



      "assign posts(postid).body = postDraft(postid).body"



      Can I somehow approach this?










      share|improve this question
















      I have 2 docs posts and postDrafts. In some point I want to publish the document from the postDraft into post.
      The content is something like body: "blah blah".



      So the trivial solution is to pull the postDraft content and then send back to posts document. Here is my code for that.



       export const publishDraftById = (postId) => async dispatch => 
      return new Promise((resolve, reject) =>
      postDraftsRef.doc(postId).get()
      .then(doc =>
      if (!doc.exists)
      reject('No such document!');
      else
      const draft = doc.data();
      postsRef.doc(postId).update(
      body: draft.body,
      date_modified: new Date()
      );
      resolve();

      )
      .catch((err) =>
      reject(err);
      console.log('Error getting documents', err);
      );
      )
      ;


      But what I really think can be helpful is a way to do something like this meta code



      "assign posts(postid).body = postDraft(postid).body"



      Can I somehow approach this?







      javascript firebase google-cloud-firestore






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 18:34









      Frank van Puffelen

      239k29382409




      239k29382409










      asked Nov 15 '18 at 18:19









      Tigran KhachikyanTigran Khachikyan

      1478




      1478






















          1 Answer
          1






          active

          oldest

          votes


















          1















          Is there a way to copy doc value into another one without pulling the data and sending back




          No, there is not. You need to get the document first in order to be able to write it back. There is no way to simply get a property within a document and write it within another document without doing this. There are no field-level permissions or access to a document. It's the entire document, or nothing.



          So if you want to read a field {body: "blah blah", then you will get the entire document and not only the property that you have write it to another document. So there are two operation involved, a read and a write operation.






          share|improve this answer























          • Hi Tigran! Is there everything alright, can I help you with other informations?

            – Alex Mamo
            Nov 16 '18 at 8:37










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325645%2fis-there-a-way-to-copy-doc-value-into-another-one-without-pulling-the-data-and-s%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1















          Is there a way to copy doc value into another one without pulling the data and sending back




          No, there is not. You need to get the document first in order to be able to write it back. There is no way to simply get a property within a document and write it within another document without doing this. There are no field-level permissions or access to a document. It's the entire document, or nothing.



          So if you want to read a field {body: "blah blah", then you will get the entire document and not only the property that you have write it to another document. So there are two operation involved, a read and a write operation.






          share|improve this answer























          • Hi Tigran! Is there everything alright, can I help you with other informations?

            – Alex Mamo
            Nov 16 '18 at 8:37















          1















          Is there a way to copy doc value into another one without pulling the data and sending back




          No, there is not. You need to get the document first in order to be able to write it back. There is no way to simply get a property within a document and write it within another document without doing this. There are no field-level permissions or access to a document. It's the entire document, or nothing.



          So if you want to read a field {body: "blah blah", then you will get the entire document and not only the property that you have write it to another document. So there are two operation involved, a read and a write operation.






          share|improve this answer























          • Hi Tigran! Is there everything alright, can I help you with other informations?

            – Alex Mamo
            Nov 16 '18 at 8:37













          1












          1








          1








          Is there a way to copy doc value into another one without pulling the data and sending back




          No, there is not. You need to get the document first in order to be able to write it back. There is no way to simply get a property within a document and write it within another document without doing this. There are no field-level permissions or access to a document. It's the entire document, or nothing.



          So if you want to read a field {body: "blah blah", then you will get the entire document and not only the property that you have write it to another document. So there are two operation involved, a read and a write operation.






          share|improve this answer














          Is there a way to copy doc value into another one without pulling the data and sending back




          No, there is not. You need to get the document first in order to be able to write it back. There is no way to simply get a property within a document and write it within another document without doing this. There are no field-level permissions or access to a document. It's the entire document, or nothing.



          So if you want to read a field {body: "blah blah", then you will get the entire document and not only the property that you have write it to another document. So there are two operation involved, a read and a write operation.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 18:26









          Alex MamoAlex Mamo

          44.8k82863




          44.8k82863












          • Hi Tigran! Is there everything alright, can I help you with other informations?

            – Alex Mamo
            Nov 16 '18 at 8:37

















          • Hi Tigran! Is there everything alright, can I help you with other informations?

            – Alex Mamo
            Nov 16 '18 at 8:37
















          Hi Tigran! Is there everything alright, can I help you with other informations?

          – Alex Mamo
          Nov 16 '18 at 8:37





          Hi Tigran! Is there everything alright, can I help you with other informations?

          – Alex Mamo
          Nov 16 '18 at 8:37



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325645%2fis-there-a-way-to-copy-doc-value-into-another-one-without-pulling-the-data-and-s%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          政党

          天津地下鉄3号線