我正试图将以下文件插入一个mongo集合中:
[
{
"text": "tryng to insert a string
with some line breaks",
}
]通过运行db.myCollection.insertMany(documentArray),documentArray只是复制粘贴这个数组。
但是我发现了一个错误:
> db.myCollection.insertMany([
... {
... "text": "tryng to insert a string
uncaught exception: SyntaxError: "" literal not terminated before end of script :
@(shell):3:37
> with some line breaks",
uncaught exception: SyntaxError: missing ( before with-statement object :
@(shell):1:5
> }
uncaught exception: SyntaxError: expected expression, got '}' :
@(shell):1:0
> ]这显然是因为它检测到新的行字符作为命令的结尾,所以Mongo认为它必须运行命令,这是不完整的。
有没有办法在\r\n和\n中保存MongoDB字符?我是否应该使用另一种方法,而不是直接使用shell?
Mongo和shell都是4.4.15版本。
发布于 2022-08-07 22:50:59
试着去做这个。关键是将换行符嵌入到字符串中。
[
{
"text": "trying to insert a string\n" +
"with some line breaks",
}
]https://stackoverflow.com/questions/73269791
复制相似问题