node.js - (node:2407) UnhandledPromiseRejectionWarning: MongoError: cannot do raw queries on admin in atlas
问题描述
在尝试发送用户数据进行注册时,应用程序返回 (node:2407) UnhandledPromiseRejectionWarning: MongoError: cannot do raw queries on admin in atlas 错误。似乎我在使用 MongoDB 的连接字符串时遇到问题,但我也不确定。我的前端使用 React/Redux,后端使用 Node.js。
我曾尝试将连接字符串替换为不同的替代方案,但它似乎不起作用。正如我从另一篇文章中看到的,我似乎需要选择更长的连接字符串,不幸的是我在 MongoDB Atlas 网站上找不到。
下面是我的连接字符串代码:
module.exports = {
mongoURI:
"mongodb+srv://willy123:willy123@devconnector-cddgi.mongodb.net/test?retryWrites=true",
secretOrKey: "secret"
};
下面我有 authActions.js,它在我提交数据后返回 authActions return err.response = undefined。
import { GET_ERRORS } from "./types";
import axios from "axios";
// Register User
export const registerUser = (userData, history) => dispatch => {
axios
.post("/api/users/register", userData)
.then(res => history.push("/login"))
.catch(err =>
dispatch({
type: GET_ERRORS,
payload: err.response.data
})
);
};
我想知道如何解决这个问题,以便我可以成功地将数据发送到我的 MongoDB 数据库。
解决方案
推荐阅读
- python - The video at python qt webbrowser no player
- javascript - 使用 javascript 在页面之间传输表格数据
- django - How to delete label of a form in Django
- arrays - MongoDB merge int arrays in one result
- javascript - Browser Copy/Paste the components
- sql-server - SQL 代理作业在 2014 年运行正常,但不是 2017 年
- php - 我在查询的 Where 语句中有 AND 运算符,我怎么知道哪个语句没有返回
- rust - 结构内的对象需要不可变和可变引用
- c - 从两个文件中逐行合并文本
- javascript - Laravel 和 Livewire:组件更改时如何执行 javascript 函数?