12

I'm using compass community v1.13.1 and have been trying to populate some sample data for couple of hours, but failed.

Found a similar issue here, I followed the first answer by @ktsangop but it didn't work.

Cant paste as a json object anyway, if I set type to string, it will be just blank string; if set type to object, can't paste the json string as a whole. image

Do I need to insert a valid json object one field by one field? or am I doing it wrong?

Syfer
  • 4,262
  • 3
  • 20
  • 37
Tyler Xue
  • 143
  • 1
  • 8
  • according to compass's doc, we should be able to paste json object. https://docs.mongodb.com/compass/current/documents/#insert-documents – Tyler Xue May 18 '18 at 02:58

4 Answers4

4

Can't believe that this is an actual issue.. for the first 2 minutes I though that something is wrong with me lol

Anyhow, I do have a (hacky) solution:

  1. Select an item and click the Edit Document button
  2. Create a new field or select existing one for editing
  3. Enter a double-quote sign "
  4. Copy the json payload
  5. Seek to the beginning of the field and remove the double-quote sign (in step 3)
  6. Save document changes

TADA!


UPDATE:

Seems like the copy-paste action will only take effect if the json is partial (valid jsons are ignored for some reason).. so I ended-up with an easier solution:

  1. Select an item and click the Edit Document button
  2. Create a new field or select existing one for editing
  3. Omit the last character from your json payload (for { "a": true } copy only { "a": true)
  4. Copy the partial json payload
  5. Seek to the end of the field add the missing character (in our sample })
  6. Save document changes
ymz
  • 6,602
  • 1
  • 20
  • 39
  • 1
    Thanks this workaround works, but what a lack of ergonomy. Incredible that we can't edit document in plain text! – Eric Dec 14 '19 at 08:33
  • 1
    Don't need to omit the last curly bracket, just only indent one space is enough. – logbasex Mar 01 '21 at 08:30
1

For future visitors: this answer might help.

Just switch the view to JSON (the two curlies button - a feature that was added after this question was raised it seems like), hit "Edit Document" upon hovering a document, and then you will be editing the JSON directly which gives you a lot of flexibility and speed.

Voicu
  • 16,921
  • 10
  • 60
  • 69
  • Thanks, this works. But MongoDB Compass has still by far the worst user experience of all apps that I am using. – Waruyama Jun 29 '21 at 18:34
0

For inserting a new document manually in MongoDB compass by following steps:

  1. Create a document and insert a new property:

for creating a document and inserting new property

  1. Add a new property inside the object:

inside the object adding new property

  1. Change the type of document property:

change the type of document property

  1. Final document is ready to insert:

final document is ready to insert

geisterfurz007
  • 5,292
  • 5
  • 33
  • 54
0

You need to Expand All than you can change type to object.

hype
  • 1