Find elements in mongo collection matching values from 3D-array











up vote
0
down vote

favorite












I have a MongoDB collection called crosses, and a three-dimensional array called originals.

Elements of the collection have 4 fields: number1, brand1, number2, brand2; the array looks like [[val1, val2], [val1, val2], [val1, val2], ...].



How should i write find() function to find every element of the collection with number1 matching val1 and brand1 matching val2 from the same element of originals array?

(i wanna get something like { number1: originals[n][0], brand1: originals[n][1] })



I do it with forEach method now but maybe there's another way?










share|improve this question


























    up vote
    0
    down vote

    favorite












    I have a MongoDB collection called crosses, and a three-dimensional array called originals.

    Elements of the collection have 4 fields: number1, brand1, number2, brand2; the array looks like [[val1, val2], [val1, val2], [val1, val2], ...].



    How should i write find() function to find every element of the collection with number1 matching val1 and brand1 matching val2 from the same element of originals array?

    (i wanna get something like { number1: originals[n][0], brand1: originals[n][1] })



    I do it with forEach method now but maybe there's another way?










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a MongoDB collection called crosses, and a three-dimensional array called originals.

      Elements of the collection have 4 fields: number1, brand1, number2, brand2; the array looks like [[val1, val2], [val1, val2], [val1, val2], ...].



      How should i write find() function to find every element of the collection with number1 matching val1 and brand1 matching val2 from the same element of originals array?

      (i wanna get something like { number1: originals[n][0], brand1: originals[n][1] })



      I do it with forEach method now but maybe there's another way?










      share|improve this question













      I have a MongoDB collection called crosses, and a three-dimensional array called originals.

      Elements of the collection have 4 fields: number1, brand1, number2, brand2; the array looks like [[val1, val2], [val1, val2], [val1, val2], ...].



      How should i write find() function to find every element of the collection with number1 matching val1 and brand1 matching val2 from the same element of originals array?

      (i wanna get something like { number1: originals[n][0], brand1: originals[n][1] })



      I do it with forEach method now but maybe there's another way?







      javascript mongodb






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 7 at 12:05









      Екатерина Тонкова

      11




      11





























          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',
          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%2f53189137%2ffind-elements-in-mongo-collection-matching-values-from-3d-array%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53189137%2ffind-elements-in-mongo-collection-matching-values-from-3d-array%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







          這個網誌中的熱門文章

          Academy of Television Arts & Sciences

          L'Équipe

          1995 France bombings