我正在使用axios和express.js API连接到我的mongo数据库。我有一个.get()请求,它适用于一个集合,不适用于任何其他集合。当前,它将连接到数据库,并且可以访问称为用户的集合之一。我在同一数据库下有另一个集合设置,称为任务,用户和任务的设置方式相同,并且在代码中的使用方式也相同。用户可以连接到数据库(获取,发布),并且调用get或post函数时任务无法连接到集合。在浏览器中查看.get()API请求时,它只是挂起,从不返回任何内容或完成请求。
任何帮助将不胜感激!
该项目位于SCRUM-150下的GitHub上。
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();
}
};
答案 0 :(得分:0)
您是否在代码中设置了任何访问控制?
另请参阅此处的mongoDB文档: https://docs.mongodb.com/manual/core/collection-level-access-control/
答案 1 :(得分:0)
这是我的解决方案: 在您的app.js中,请执行以下操作:
www.xyz.com/def/.../jki/m/abc
在您的路线上有这个
let mongoose = require('mongoose');
mongoose.connect('Your/Database/Url', {
keepAlive : true,
reconnectTries: 2,
useMongoClient: true
});