Help to create a database from Compass

Hi

I try to create automatically a database from Compass

use db1
db.col1.insert( { "x":1 } )

2 questions :
1) is it the good process to use the "Documents" menu and to do "ADD DATA" and "Insert document"?
2) I yes, when I run the query, I have the message "Insert not permitted while document contains errors."
Could you help please?





Hi @jip31,

  1. “Documents” tab → “ADD DATA” → “Insert document” is a good way to insert documents in instances where you want to insert one or a few documents. Other options for adding data through Compass include:
  • Importing data into Compass if you have a JSON or CSV file (“Documents” tab → “ADD DATA” → “Import file”).
  • Using the insertOne(), insertMany(), or bulkWrite() in the embedded MongoDB Shell (mongosh). It seems like you’ve already tried insert().
  1. A few questions to give me more context so that I can help you:
  • Are you running the use db1 and db.col1.insert( { "x":1 } ) commands in the embedded shell in Compass?
  • Is { "x":1 } the exact syntax of the document you are looking to add to the database db1?

Thanks,
Sahi

1 Like

Hi Sahi
Thanks for the first point
Concerning the second point, I try to run the use db1 and db.col1.insert( { "x":1 } ) in Compass
image
Sorry, because I am a rookie but except if I am mistaken, it’s not possible to do that in Compass but just in mongosh?

Yes { "x":1 } is the exact syntax

Hi Jean @jip31,

What you have pulled up in the screenshot is the query bar in Compass which can be used to filter documents based on specified criteria. You can find more information on how to use that query bar to find specific documents here: https://www.mongodb.com/docs/compass/current/query/filter/.

Unfortunately, the query bar cannot be used for inserting documents. However, you can run those 2 commands in the embedded shell (mongosh) in Compass to add a document to db.col1. Once you run the commands in the embedded mongosh, you can click on the refresh button next to “Databases” to see the data you added via the embedded mongosh in Compass. I have attached a screenshot of what this should look like for your reference.

Hope this helps! Let me know if you have any other questions.

Thanks,
Sahi

1 Like

Thanks a lot Sahi!!!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.