在Studio 3T中,我已经创建了一个集合,我要在其中添加一个文档,然后弹出窗口显示标题为>>Insert JSON Document<<要将数据添加到文档中,然后我编写了这些项。
{
"_id" : "5c18e1892998bdb3b3d355bf",
"title" : "REST",
"content" : "REST is short for REpresentational State Transfer. IIt's an architectural style for designing APIs."
}
{
"_id" : ObjectId("5c139771d79ac8eac11e754a"),
"title" : "API",
"content" : "API stands for Application Programming Interface. It is a set of subroutine definitions, communication protocols, and tools for building software. In general terms, it is a set of clearly defined methods of communication among various components. A good API makes it easier to develop a computer program by providing all the building blocks, which are then put together by the programmer."
}
{
"_id" : ObjectId("5c1398aad79ac8eac11e7561"),
"title" : "Bootstrap",
"content" : "This is a framework developed by Twitter that contains pre-made front-end templates for web design"
}
{
"_id" : ObjectId("5c1398ecd79ac8eac11e7567"),
"title" : "DOM",
"content" : "The Document Object Model is like an API for interacting with our HTML"
}
{
"_id" : "5c18f35cde40ab6cc551cd60",
"title" : "Jack Bauer",
"content" : "Jack Bauer once stepped into quicksand. The quicksand couldn't escape and nearly drowned.",
"__v" : 0
}
之后,当我单击Add Document按钮时,出现另一个标题为>>JSON Validation<<的弹出窗口,在该窗口下面显示“在第8行检测到孤立字符,第1列”。而且我不能一次插入这些文档。
如何在文档中一次插入所有这些对象?
4条答案
按热度按时间fhg3lkii1#
当我试图一次插入多个对象时,我也遇到了同样的问题。我的解决方案是单独添加对象。它知道这需要时间,但我找不到其他任何方法来做它。
0tdrvxhp2#
这是一个限制,在此之前不受支持。您可以运行
insertMany
查询Github link
或者,如果您不想运行直接查询,也可以导入文档。
zlwx9yxi3#
将JSON文档复制到剪贴板,然后转到集合和Control/Command V,将剪贴板粘贴到集合中。系统将提示您“从剪贴板导入文档”--单击“确定”,完成后,刷新您的视图以查看新导入的文档。
背景:正如它所说,插入JSON文档是针对单个JSON文档的。您看到的错误是因为它检测到第二个JSON文档开始。通过导入可以更好地处理多个JSON文档插入,如果您将JSON文档粘贴到一个集合中,它会自动触发从剪贴板的导入。
bf1o4zei4#
很简单。选择要输入到集合中的所有JSON数据,并将其复制到剪贴板(在PC上为Ctrl+C,在MAC上为Command+C)。
1.在Studio3T中,右键单击要在其中插入项目的文档。
1.从菜单中选择“导入数据...”
1.保留预选的第一个选项“JSON-Mongo shell...”
1.点击[配置]确认选择
1.点击“从剪贴板粘贴”,然后点击绿色的“运行”按钮。
就是这样:),自2022年10月2日起生效。