Is there a way to copy doc value into another one without pulling the data and sending back
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
add a comment |
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
add a comment |
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
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
javascript firebase google-cloud-firestore
edited Nov 15 '18 at 18:34
Frank van Puffelen
239k29382409
239k29382409
asked Nov 15 '18 at 18:19
Tigran KhachikyanTigran Khachikyan
1478
1478
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
Hi Tigran! Is there everything alright, can I help you with other informations?
– Alex Mamo
Nov 16 '18 at 8:37
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Hi Tigran! Is there everything alright, can I help you with other informations?
– Alex Mamo
Nov 16 '18 at 8:37
add a comment |
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.
Hi Tigran! Is there everything alright, can I help you with other informations?
– Alex Mamo
Nov 16 '18 at 8:37
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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