How to update a collection using another collection as a reference?How to query MongoDB with “like”?How do I drop a MongoDB database from the command line?How to list all collections in the mongo shell?mongodb - strategy to ensure save data in different collections like a transaction at application level“Large data” work flows using pandasMongoDB update multiple collectionsSimple-schema wont updateCompare a mongo diff query into mongodbHow to perform equi join in mongodb?MongoDB: Efficient $nin operator
SUM Case Logic with Distinct
What's the difference between a share and a stock?
Dissuading my girlfriend from a scam
Project Euler Problem 45
Is it rude to ask my opponent to resign an online game when they have a lost endgame?
Is every coset of a group closed under taking inverses?
A magician's sleight of hand
Why does the seven segment display have decimal point at the right?
Low quality postdoc application and deadline extension
Shoes for commuting
Professor refuses to write a recommendation letter to students who haven't written a research paper with him
What are some countries where you can be imprisoned for reading or owning a Bible?
Why do old games use flashing as means of showing damage?
In-universe, why does Doc Brown program the time machine to go to 1955?
Is the Levitate spell supposed to basically disable a melee-based enemy?
Who are these people in this satirical cartoon of the Congress of Verona?
What quests do you need to stop at before you make an enemy of a faction for each faction?
How do I stop making people jump at home and at work?
Why did Boris Johnson call for new elections?
Can doublestrike kill a creature with totem armor?
First Number to Contain Each Letter
Was "The Hobbit" ever abridged?
Never make public members virtual/abstract - really?
Would you recommend a keyboard for beginners with or without lights in keys for learning?
How to update a collection using another collection as a reference?
How to query MongoDB with “like”?How do I drop a MongoDB database from the command line?How to list all collections in the mongo shell?mongodb - strategy to ensure save data in different collections like a transaction at application level“Large data” work flows using pandasMongoDB update multiple collectionsSimple-schema wont updateCompare a mongo diff query into mongodbHow to perform equi join in mongodb?MongoDB: Efficient $nin operator
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have 2 collections in MongoDB 3.4.7:
Collection1
Id: 54648364848
Internal Code: 50
Collection2
Id: 54648364848
Quantity: -10
Would you like to update the Quantity field of Collection2 using the Internal Code field of Collection1? Given that the field they have in common is the Id, but I do not want to specify it in the sentence (because in the system in question, the ID is a gigantic numbering). A rude example of reasoning in SQL:
update Collection2
set Collection2.Quantity = 25
where Collection1.Id = Collection2.Id and
Collection1.Internal Code = 50
mongodb
add a comment |
I have 2 collections in MongoDB 3.4.7:
Collection1
Id: 54648364848
Internal Code: 50
Collection2
Id: 54648364848
Quantity: -10
Would you like to update the Quantity field of Collection2 using the Internal Code field of Collection1? Given that the field they have in common is the Id, but I do not want to specify it in the sentence (because in the system in question, the ID is a gigantic numbering). A rude example of reasoning in SQL:
update Collection2
set Collection2.Quantity = 25
where Collection1.Id = Collection2.Id and
Collection1.Internal Code = 50
mongodb
MongoDB does not support "join statements" in updating. You update via the "foreign collection" you actually want to update and not based on conditions in the master collection. If you need to do that, you can query the master collection for it's condition, and then feed to the "foreign update" using$in
for the related Id values. So two statements to the server instead of one. But in truth, if you need to do that it's more of an indicator of bad design. Change the design or use an RDBMS.
– Neil Lunn
Mar 28 at 9:50
add a comment |
I have 2 collections in MongoDB 3.4.7:
Collection1
Id: 54648364848
Internal Code: 50
Collection2
Id: 54648364848
Quantity: -10
Would you like to update the Quantity field of Collection2 using the Internal Code field of Collection1? Given that the field they have in common is the Id, but I do not want to specify it in the sentence (because in the system in question, the ID is a gigantic numbering). A rude example of reasoning in SQL:
update Collection2
set Collection2.Quantity = 25
where Collection1.Id = Collection2.Id and
Collection1.Internal Code = 50
mongodb
I have 2 collections in MongoDB 3.4.7:
Collection1
Id: 54648364848
Internal Code: 50
Collection2
Id: 54648364848
Quantity: -10
Would you like to update the Quantity field of Collection2 using the Internal Code field of Collection1? Given that the field they have in common is the Id, but I do not want to specify it in the sentence (because in the system in question, the ID is a gigantic numbering). A rude example of reasoning in SQL:
update Collection2
set Collection2.Quantity = 25
where Collection1.Id = Collection2.Id and
Collection1.Internal Code = 50
mongodb
mongodb
asked Mar 28 at 3:42
WashingtonWashington
1
1
MongoDB does not support "join statements" in updating. You update via the "foreign collection" you actually want to update and not based on conditions in the master collection. If you need to do that, you can query the master collection for it's condition, and then feed to the "foreign update" using$in
for the related Id values. So two statements to the server instead of one. But in truth, if you need to do that it's more of an indicator of bad design. Change the design or use an RDBMS.
– Neil Lunn
Mar 28 at 9:50
add a comment |
MongoDB does not support "join statements" in updating. You update via the "foreign collection" you actually want to update and not based on conditions in the master collection. If you need to do that, you can query the master collection for it's condition, and then feed to the "foreign update" using$in
for the related Id values. So two statements to the server instead of one. But in truth, if you need to do that it's more of an indicator of bad design. Change the design or use an RDBMS.
– Neil Lunn
Mar 28 at 9:50
MongoDB does not support "join statements" in updating. You update via the "foreign collection" you actually want to update and not based on conditions in the master collection. If you need to do that, you can query the master collection for it's condition, and then feed to the "foreign update" using
$in
for the related Id values. So two statements to the server instead of one. But in truth, if you need to do that it's more of an indicator of bad design. Change the design or use an RDBMS.– Neil Lunn
Mar 28 at 9:50
MongoDB does not support "join statements" in updating. You update via the "foreign collection" you actually want to update and not based on conditions in the master collection. If you need to do that, you can query the master collection for it's condition, and then feed to the "foreign update" using
$in
for the related Id values. So two statements to the server instead of one. But in truth, if you need to do that it's more of an indicator of bad design. Change the design or use an RDBMS.– Neil Lunn
Mar 28 at 9:50
add a comment |
0
active
oldest
votes
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%2f55389834%2fhow-to-update-a-collection-using-another-collection-as-a-reference%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
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%2f55389834%2fhow-to-update-a-collection-using-another-collection-as-a-reference%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
MongoDB does not support "join statements" in updating. You update via the "foreign collection" you actually want to update and not based on conditions in the master collection. If you need to do that, you can query the master collection for it's condition, and then feed to the "foreign update" using
$in
for the related Id values. So two statements to the server instead of one. But in truth, if you need to do that it's more of an indicator of bad design. Change the design or use an RDBMS.– Neil Lunn
Mar 28 at 9:50