Issue Connecting to MongoDB collections










2















I am using axios and express.js API to connect to my mongo DB. I have a .get() request that works for one collection and doesn't work for any other collection. This currently will connect to the database and can access one of the collections called users. I have another collection setup under the same database called tasks, I have both users and tasks setup the same way and being used the same way in the code. The users can connect to the DB (get, post) and the tasks fails to connect to the collection when calling the get or the post functions. When viewing the .get() API request in the browser it just hangs and never returns anything or finishes the request.



any help would be greatly appreciated!



The project is on GitHub under SCRUM-150.



API connection
MONGO_URI=mongodb://localhost:27017/mydb

Working

methods:
//load all users from DB, we call this often to make sure the data is up to date
load()
http
.get("users")
.then(response =>
this.users = response.data.users;
)
.catch(e =>
this.errors.push(e);
);
,

//opens delete dialog
setupDelete(user)
this.userToDelete = user;
this.deleteDialog = true;
,

//opens edit dialog
setupEdit(user)
Object.keys(user).forEach(key =>
this.userToEdit[key] = user[key];
);
this.editName = user.name;
this.editDialog = true;
,

//build the alert info for us
//Will emit an alert, followed by a boolean for success, the type of call made, and the name of the
//resource we are working on
alert(success, callName, resource)
console.log('Page Alerting')
this.$emit('alert', success, callName, resource)
this.load()

,

//get those users
mounted()
this.load();

};


Broken
methods:
//load all tasks from DB, we call this often to make sure the data is up to date
load()
http
.get("tasks")
.then(response =>
this.tasks = response.data.tasks
)
.catch(e =>
this.errors.push(e);
);
,

//opens delete dialog
setupDelete(tasks)
this.taskToDelete = tasks;
this.deleteDialog = true;
,

//opens edit dialog
setupEdit(tasks)
Object.keys(tasks).forEach(key =>
this.taskToEdit[key] = tasks[key];
);
this.editName = tasks.name;
this.editDialog = true;
,

//build the alert info for us
//Will emit an alert, followed by a boolean for success, the type of call made, and the name of the
//resource we are working on
alert(success, callName, resource)
console.log('Page Alerting')
this.$emit('alert', success, callName, resource)
this.load()

,

//get those tasks
mounted()
this.load();

};









share|improve this question


























    2















    I am using axios and express.js API to connect to my mongo DB. I have a .get() request that works for one collection and doesn't work for any other collection. This currently will connect to the database and can access one of the collections called users. I have another collection setup under the same database called tasks, I have both users and tasks setup the same way and being used the same way in the code. The users can connect to the DB (get, post) and the tasks fails to connect to the collection when calling the get or the post functions. When viewing the .get() API request in the browser it just hangs and never returns anything or finishes the request.



    any help would be greatly appreciated!



    The project is on GitHub under SCRUM-150.



    API connection
    MONGO_URI=mongodb://localhost:27017/mydb

    Working

    methods:
    //load all users from DB, we call this often to make sure the data is up to date
    load()
    http
    .get("users")
    .then(response =>
    this.users = response.data.users;
    )
    .catch(e =>
    this.errors.push(e);
    );
    ,

    //opens delete dialog
    setupDelete(user)
    this.userToDelete = user;
    this.deleteDialog = true;
    ,

    //opens edit dialog
    setupEdit(user)
    Object.keys(user).forEach(key =>
    this.userToEdit[key] = user[key];
    );
    this.editName = user.name;
    this.editDialog = true;
    ,

    //build the alert info for us
    //Will emit an alert, followed by a boolean for success, the type of call made, and the name of the
    //resource we are working on
    alert(success, callName, resource)
    console.log('Page Alerting')
    this.$emit('alert', success, callName, resource)
    this.load()

    ,

    //get those users
    mounted()
    this.load();

    };


    Broken
    methods:
    //load all tasks from DB, we call this often to make sure the data is up to date
    load()
    http
    .get("tasks")
    .then(response =>
    this.tasks = response.data.tasks
    )
    .catch(e =>
    this.errors.push(e);
    );
    ,

    //opens delete dialog
    setupDelete(tasks)
    this.taskToDelete = tasks;
    this.deleteDialog = true;
    ,

    //opens edit dialog
    setupEdit(tasks)
    Object.keys(tasks).forEach(key =>
    this.taskToEdit[key] = tasks[key];
    );
    this.editName = tasks.name;
    this.editDialog = true;
    ,

    //build the alert info for us
    //Will emit an alert, followed by a boolean for success, the type of call made, and the name of the
    //resource we are working on
    alert(success, callName, resource)
    console.log('Page Alerting')
    this.$emit('alert', success, callName, resource)
    this.load()

    ,

    //get those tasks
    mounted()
    this.load();

    };









    share|improve this question
























      2












      2








      2








      I am using axios and express.js API to connect to my mongo DB. I have a .get() request that works for one collection and doesn't work for any other collection. This currently will connect to the database and can access one of the collections called users. I have another collection setup under the same database called tasks, I have both users and tasks setup the same way and being used the same way in the code. The users can connect to the DB (get, post) and the tasks fails to connect to the collection when calling the get or the post functions. When viewing the .get() API request in the browser it just hangs and never returns anything or finishes the request.



      any help would be greatly appreciated!



      The project is on GitHub under SCRUM-150.



      API connection
      MONGO_URI=mongodb://localhost:27017/mydb

      Working

      methods:
      //load all users from DB, we call this often to make sure the data is up to date
      load()
      http
      .get("users")
      .then(response =>
      this.users = response.data.users;
      )
      .catch(e =>
      this.errors.push(e);
      );
      ,

      //opens delete dialog
      setupDelete(user)
      this.userToDelete = user;
      this.deleteDialog = true;
      ,

      //opens edit dialog
      setupEdit(user)
      Object.keys(user).forEach(key =>
      this.userToEdit[key] = user[key];
      );
      this.editName = user.name;
      this.editDialog = true;
      ,

      //build the alert info for us
      //Will emit an alert, followed by a boolean for success, the type of call made, and the name of the
      //resource we are working on
      alert(success, callName, resource)
      console.log('Page Alerting')
      this.$emit('alert', success, callName, resource)
      this.load()

      ,

      //get those users
      mounted()
      this.load();

      };


      Broken
      methods:
      //load all tasks from DB, we call this often to make sure the data is up to date
      load()
      http
      .get("tasks")
      .then(response =>
      this.tasks = response.data.tasks
      )
      .catch(e =>
      this.errors.push(e);
      );
      ,

      //opens delete dialog
      setupDelete(tasks)
      this.taskToDelete = tasks;
      this.deleteDialog = true;
      ,

      //opens edit dialog
      setupEdit(tasks)
      Object.keys(tasks).forEach(key =>
      this.taskToEdit[key] = tasks[key];
      );
      this.editName = tasks.name;
      this.editDialog = true;
      ,

      //build the alert info for us
      //Will emit an alert, followed by a boolean for success, the type of call made, and the name of the
      //resource we are working on
      alert(success, callName, resource)
      console.log('Page Alerting')
      this.$emit('alert', success, callName, resource)
      this.load()

      ,

      //get those tasks
      mounted()
      this.load();

      };









      share|improve this question














      I am using axios and express.js API to connect to my mongo DB. I have a .get() request that works for one collection and doesn't work for any other collection. This currently will connect to the database and can access one of the collections called users. I have another collection setup under the same database called tasks, I have both users and tasks setup the same way and being used the same way in the code. The users can connect to the DB (get, post) and the tasks fails to connect to the collection when calling the get or the post functions. When viewing the .get() API request in the browser it just hangs and never returns anything or finishes the request.



      any help would be greatly appreciated!



      The project is on GitHub under SCRUM-150.



      API connection
      MONGO_URI=mongodb://localhost:27017/mydb

      Working

      methods:
      //load all users from DB, we call this often to make sure the data is up to date
      load()
      http
      .get("users")
      .then(response =>
      this.users = response.data.users;
      )
      .catch(e =>
      this.errors.push(e);
      );
      ,

      //opens delete dialog
      setupDelete(user)
      this.userToDelete = user;
      this.deleteDialog = true;
      ,

      //opens edit dialog
      setupEdit(user)
      Object.keys(user).forEach(key =>
      this.userToEdit[key] = user[key];
      );
      this.editName = user.name;
      this.editDialog = true;
      ,

      //build the alert info for us
      //Will emit an alert, followed by a boolean for success, the type of call made, and the name of the
      //resource we are working on
      alert(success, callName, resource)
      console.log('Page Alerting')
      this.$emit('alert', success, callName, resource)
      this.load()

      ,

      //get those users
      mounted()
      this.load();

      };


      Broken
      methods:
      //load all tasks from DB, we call this often to make sure the data is up to date
      load()
      http
      .get("tasks")
      .then(response =>
      this.tasks = response.data.tasks
      )
      .catch(e =>
      this.errors.push(e);
      );
      ,

      //opens delete dialog
      setupDelete(tasks)
      this.taskToDelete = tasks;
      this.deleteDialog = true;
      ,

      //opens edit dialog
      setupEdit(tasks)
      Object.keys(tasks).forEach(key =>
      this.taskToEdit[key] = tasks[key];
      );
      this.editName = tasks.name;
      this.editDialog = true;
      ,

      //build the alert info for us
      //Will emit an alert, followed by a boolean for success, the type of call made, and the name of the
      //resource we are working on
      alert(success, callName, resource)
      console.log('Page Alerting')
      this.$emit('alert', success, callName, resource)
      this.load()

      ,

      //get those tasks
      mounted()
      this.load();

      };






      mongodb express vue.js mongoose axios






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 19:10









      TgilletteTgillette

      111




      111






















          2 Answers
          2






          active

          oldest

          votes


















          0














          Are you setting any access controls in the code?



          Also refer to mongoDB's documentation here:
          https://docs.mongodb.com/manual/core/collection-level-access-control/






          share|improve this answer























          • Currently no, everything is open to all users.

            – Tgillette
            Nov 14 '18 at 23:47


















          0














          Here is my solution:
          In your app.js, have this:



          let mongoose = require('mongoose');

          mongoose.connect('Your/Database/Url',
          keepAlive : true,
          reconnectTries: 2,
          useMongoClient: true
          );


          In your route have this:



          let mongoose = require('mongoose');
          let db = mongoose.connection;
          fetchAndSendDatabase('yourCollectionName', db);

          function fetchAndSendDatabase(dbName, db)
          db.collection(dbName).find().toArray(function(err, result)
          if( err )
          console.log("couldn't get database items. " + err);

          else
          console.log('Database received successfully');

          );






          share|improve this answer

























          • Where would this go to get this to work? would this go in the routes.js or the app.js file?

            – Tgillette
            Nov 14 '18 at 23:48











          • @Tgillette updated my answer

            – Hamid
            Nov 15 '18 at 15:13










          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%2f53307212%2fissue-connecting-to-mongodb-collections%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Are you setting any access controls in the code?



          Also refer to mongoDB's documentation here:
          https://docs.mongodb.com/manual/core/collection-level-access-control/






          share|improve this answer























          • Currently no, everything is open to all users.

            – Tgillette
            Nov 14 '18 at 23:47















          0














          Are you setting any access controls in the code?



          Also refer to mongoDB's documentation here:
          https://docs.mongodb.com/manual/core/collection-level-access-control/






          share|improve this answer























          • Currently no, everything is open to all users.

            – Tgillette
            Nov 14 '18 at 23:47













          0












          0








          0







          Are you setting any access controls in the code?



          Also refer to mongoDB's documentation here:
          https://docs.mongodb.com/manual/core/collection-level-access-control/






          share|improve this answer













          Are you setting any access controls in the code?



          Also refer to mongoDB's documentation here:
          https://docs.mongodb.com/manual/core/collection-level-access-control/







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 19:23









          derekjgrovederekjgrove

          64




          64












          • Currently no, everything is open to all users.

            – Tgillette
            Nov 14 '18 at 23:47

















          • Currently no, everything is open to all users.

            – Tgillette
            Nov 14 '18 at 23:47
















          Currently no, everything is open to all users.

          – Tgillette
          Nov 14 '18 at 23:47





          Currently no, everything is open to all users.

          – Tgillette
          Nov 14 '18 at 23:47













          0














          Here is my solution:
          In your app.js, have this:



          let mongoose = require('mongoose');

          mongoose.connect('Your/Database/Url',
          keepAlive : true,
          reconnectTries: 2,
          useMongoClient: true
          );


          In your route have this:



          let mongoose = require('mongoose');
          let db = mongoose.connection;
          fetchAndSendDatabase('yourCollectionName', db);

          function fetchAndSendDatabase(dbName, db)
          db.collection(dbName).find().toArray(function(err, result)
          if( err )
          console.log("couldn't get database items. " + err);

          else
          console.log('Database received successfully');

          );






          share|improve this answer

























          • Where would this go to get this to work? would this go in the routes.js or the app.js file?

            – Tgillette
            Nov 14 '18 at 23:48











          • @Tgillette updated my answer

            – Hamid
            Nov 15 '18 at 15:13















          0














          Here is my solution:
          In your app.js, have this:



          let mongoose = require('mongoose');

          mongoose.connect('Your/Database/Url',
          keepAlive : true,
          reconnectTries: 2,
          useMongoClient: true
          );


          In your route have this:



          let mongoose = require('mongoose');
          let db = mongoose.connection;
          fetchAndSendDatabase('yourCollectionName', db);

          function fetchAndSendDatabase(dbName, db)
          db.collection(dbName).find().toArray(function(err, result)
          if( err )
          console.log("couldn't get database items. " + err);

          else
          console.log('Database received successfully');

          );






          share|improve this answer

























          • Where would this go to get this to work? would this go in the routes.js or the app.js file?

            – Tgillette
            Nov 14 '18 at 23:48











          • @Tgillette updated my answer

            – Hamid
            Nov 15 '18 at 15:13













          0












          0








          0







          Here is my solution:
          In your app.js, have this:



          let mongoose = require('mongoose');

          mongoose.connect('Your/Database/Url',
          keepAlive : true,
          reconnectTries: 2,
          useMongoClient: true
          );


          In your route have this:



          let mongoose = require('mongoose');
          let db = mongoose.connection;
          fetchAndSendDatabase('yourCollectionName', db);

          function fetchAndSendDatabase(dbName, db)
          db.collection(dbName).find().toArray(function(err, result)
          if( err )
          console.log("couldn't get database items. " + err);

          else
          console.log('Database received successfully');

          );






          share|improve this answer















          Here is my solution:
          In your app.js, have this:



          let mongoose = require('mongoose');

          mongoose.connect('Your/Database/Url',
          keepAlive : true,
          reconnectTries: 2,
          useMongoClient: true
          );


          In your route have this:



          let mongoose = require('mongoose');
          let db = mongoose.connection;
          fetchAndSendDatabase('yourCollectionName', db);

          function fetchAndSendDatabase(dbName, db)
          db.collection(dbName).find().toArray(function(err, result)
          if( err )
          console.log("couldn't get database items. " + err);

          else
          console.log('Database received successfully');

          );







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 15 '18 at 15:13

























          answered Nov 14 '18 at 19:52









          HamidHamid

          1,3492135




          1,3492135












          • Where would this go to get this to work? would this go in the routes.js or the app.js file?

            – Tgillette
            Nov 14 '18 at 23:48











          • @Tgillette updated my answer

            – Hamid
            Nov 15 '18 at 15:13

















          • Where would this go to get this to work? would this go in the routes.js or the app.js file?

            – Tgillette
            Nov 14 '18 at 23:48











          • @Tgillette updated my answer

            – Hamid
            Nov 15 '18 at 15:13
















          Where would this go to get this to work? would this go in the routes.js or the app.js file?

          – Tgillette
          Nov 14 '18 at 23:48





          Where would this go to get this to work? would this go in the routes.js or the app.js file?

          – Tgillette
          Nov 14 '18 at 23:48













          @Tgillette updated my answer

          – Hamid
          Nov 15 '18 at 15:13





          @Tgillette updated my answer

          – Hamid
          Nov 15 '18 at 15:13

















          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%2f53307212%2fissue-connecting-to-mongodb-collections%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

          ReactJS Fetched API data displays live - need Data displayed static

          Evgeni Malkin