首页 > 解决方案 > (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 数据库。

标签: node.jsreactjsmongodbredux

解决方案


推荐阅读