首页 > 解决方案 > 从 mongo 创建的对象在 psql 中输入数据

问题描述

我正在我的数据库中输入来自 mongo 的 _id 但答案很奇怪,当我

console.log(createdPlace._id);

我得到一个常规的答案

5f43b0fdc9d92c05282360a8

const addTodo = async (req, res, next) => {
  const { content } = req.body;

  const createdPlace = new Url({
    content: content,
    enable: false,
  });
  // Sending it To Mongo
  try {
    console.log(createdPlace._id);
    await createdPlace.save();
    await pool.query(
      "INSERT INTO todo (todo_id ,content, enable) VALUES ($1, $2, $3)",
      [createdPlace._id, content, false]
    );
  } catch (err) {
    const error = new HttpError("Creating Place fails");
    return next(error);
  }

  res.sendStatus(200);
};

数据库的输出是

  {
    "todo_id": "\"5f43b0fdc9d92c05282360a8\"",
    "content": "first sending to with sasasddaame id",
    "enable": false
  }

这让我在 todo_id 末尾的这个“\”\“”发疯了希望得到帮助。

标签: javascriptnode.jsdatabasemongodbpostgresql

解决方案


推荐阅读