Issue Connecting to MongoDB collections

Multi tool use
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
add a comment |
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
add a comment |
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
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
mongodb express vue.js mongoose axios
asked Nov 14 '18 at 19:10
TgilletteTgillette
111
111
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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/
Currently no, everything is open to all users.
– Tgillette
Nov 14 '18 at 23:47
add a comment |
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');
);
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
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%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
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/
Currently no, everything is open to all users.
– Tgillette
Nov 14 '18 at 23:47
add a comment |
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/
Currently no, everything is open to all users.
– Tgillette
Nov 14 '18 at 23:47
add a comment |
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/
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/
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
add a comment |
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
add a comment |
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');
);
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
add a comment |
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');
);
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
add a comment |
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');
);
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');
);
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
add a comment |
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
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%2f53307212%2fissue-connecting-to-mongodb-collections%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
IG4KZezOqPW,qI,zKyJlcFBkxgPpVL,g L 5ucWS sW