MongoDB Compass可视插入子文档 [英] MongoDB Compass Visually Insert Sub-Document

查看:413
本文介绍了MongoDB Compass可视插入子文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MongoDB Compass直观地构建我的收藏集.

I'm using MongoDB Compass to visually build my collection.

在突出显示的部分中,我看不到要插入子文档的文档"类型.我做对了吗?

In the highlighted section, I don't see a "Document" type to insert a sub-Document. Am I doing it the right way?

推荐答案

对于字段值,您可以粘贴可通过以下方式解析的有效JSON: JavaScript的JSON.parse.

For the field values, you can paste valid JSON that can be parsed by JavaScript’s JSON.parse.

如果粘贴的JSON是对象(即文档),则密钥必须为 用双引号引起来,并且可以转义.首先 字符必须为左花括号{,最后一个必须为右花括号 大括号}:

If the pasted JSON is an Object (i.e. a document), the keys must be quoted in double quotes and are permitted to be escaped. The first character must be left curly brace { and the last must be right curly brace }:

{
  "email": "test@example.com",
  "phone": "555-555-1212"
}

但是不幸的是,该过程确实违反直觉,因为如果您从上述示例复制JSON对象,您将不能粘贴到字段值中,除非您首先输入一个空格字符.

But unfortunately the process is really counterintuitive, because if you copy the JSON object from the above example, you will not be able to paste it inside the field value unless you firstly type something i.e. a space character.

但是,如果您的对象不是有效的JSON,则会将其粘贴(!)而不进行解析(?),并将其另存为字符串.

But if your object is not a valid JSON, it will be pasted (!) but not parsed (?) and it will be saved as a string.

无论如何,即使您设法存储对象,也将无法轻松地对其进行编辑,并且最终将其复制并粘贴到外部文本编辑器中,以实现您的目标.

Anyway even if you manage to store your object, you will not be able to edit it easily, and you will end up copying and pasting to an external text editor in order to achive your goal.

编辑:

您可以尝试使用此客户端 Robo 3T ,它使您可以大量编辑文档结构更容易.有趣的是,如果您使用Robo 3T编辑文档并在Compass中重新加载文档,它将使您始终按预期进行操作...因此,它一定是Compass UI的问题/错误.

You can try using this client Robo 3T which lets you edit the document structure much more easily. Funny thing, if you edit the document with Robo 3T and reload the document in Compass, it will let you do what you intended all along... So it must be a kind of Compass UI issue/bug.

这篇关于MongoDB Compass可视插入子文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆