Javascript 反斜杠在将id写入mongoDb时打印

Javascript 反斜杠在将id写入mongoDb时打印,javascript,angularjs,node.js,mongodb,Javascript,Angularjs,Node.js,Mongodb,我正在以以下方式将id从angular js传递到nodejs服务器: formData.append(“proId”,JSON.stringify($scope.pid)) 我还可以在服务器端检索id,但当我将其发布到MongoDB时,它会将back shlahes添加到id中。 例如: “\”5a0fc8ad4a9a9c2cd81a8853\”,它不应包含\&extra“逗号。 为什么会这样呢?这就是JSON.stringify对字符串所做的: → node -pe 'JSON.stri

我正在以以下方式将id从angular js传递到nodejs服务器:

formData.append(“proId”,JSON.stringify($scope.pid))


我还可以在服务器端检索
id
,但当我将其发布到MongoDB时,它会将
back shlahes
添加到id中。
例如:
“\”5a0fc8ad4a9a9c2cd81a8853\”
,它不应包含
\
&extra
逗号。


为什么会这样呢?

这就是
JSON.stringify
对字符串所做的:

→ node -pe 'JSON.stringify("5a0fc8ad4a9a9c2cd81a8853")'
"5a0fc8ad4a9a9c2cd81a8853"
您可能需要在服务器端解析它

→ node -pe 'JSON.parse("\"5a0fc8ad4a9a9c2cd81a8853\"")'
5a0fc8ad4a9a9c2cd81a8853
或者首先不要对变量进行JSON编码