Insert not permitted while document contains errors

I am unable to insert a document into MoviesScratch collection on my Sandbox cluster using Compass. I have verified that I have READ / Write on Any Database. I read a previous topic that had a similar issue where the result was to enclose the field in quotes. I have tried that as well. Compass version 1.20.5 does not behave anything like the version in the training video to Insert a Document. I have tried adding and removing different pieces of the data to be inserted to no avail. Please advise.
Thank you.

The document contains an error.

I think the quotes arround ObjectID and the : just after are wrong.

1 Like

Here’s a visual:

image

Thank you for your suggestion. I have tried various syntax. Even with the quotes around the ObjectID removed, it still says there is an error.

I have managed to successfully add a document with either the title or the icmb field, but not both into one document. Plus, you may notice on the right side of the insert panel, the datatypes do not show as in the video.
image
Thanks again for you input.

You fixed 2 of 3 problems. Please have a look at the screenshot and @steevej-1495’s comment once more.

Ah! Great hint. I missed the “:”. Still the same with that removed. Even I remove that whole line. Still has an error. The odd thing to me is that in the video, the _id showed up on it’s own.
image

Thanks once again! I appreciate the help.

ObjectId instead of ObjectID :+1:

Another good idea. Still says errors though. In the video, the syntax appears to be ObjectID.
image

image

Thanks again.

You might need a comma between each field.

Good catch @steevej-1495… I didn’t notice that.

And it looks like the latest version of Compass (1.20.5) doesn’t allow manual insertions of ObjectId() values into the _id field anymore. So you’d need either remove the _id part or insert any other datatype like a String, Number etc.

Yep, tried the coma as you would use them in a SQL Statement, but this is nosql so it didn’t work either. :slight_smile:

Thanks again for all your help!

You might have missed my last post. The lectures are using a much older version of Compass and there’s been some changes since then. So in addition to including the commas, here’s what you need to do…

Eureka! I was able to insert a document!
007 - Yes I hadn’t received your previous post before trying before. But now it’s working. Sorry for being so thick headed and thanks to everyone for all your help!

MJB

BTW, here is the final syntax for any who may need it.

{
“title” : “Rocky”,
“year” : “1976”,
“imdb” : “tt0075148”
}

1 Like

You weren’t, it’s not your fault. The lectures are a bit outdated and the MongoDB Curriculum team have confirmed that all the courses will soon get an upgrade.

For other readers, in the latest version of Compass, version 1.20.5, you have two ways to manually insert documents:

  1. The first method uses Extended JSON (v2) syntax that allows for single or multiple documents to be inserted. This is new in 1.20.5:
    image
    In this case you have to use $oid if you want to override the auto-generated ObjectId() of the _id field. Otherwise, omit the _id key-value pair and it will be automatically generated post insertion, like @Michael_38028’s example:

    {
       "title" : "Rocky",
       "year" : "1976",
       "imdb" : "tt0075148"
    }
    

    NB: Ensure that you use straight quotes (") and not inverted quotes ()

  2. The second method is a single document insertion which corresponds to the lecture, however, in this version (1.20.5) you will not be able to edit the ObjectId("<immutable>") of the _id field:
    image

2 Likes

Hi @007_jb,

Thanks for aggregating the solution in one post.

Thanks,
Shubham Ranjan
Curriculum Services Engineer

1 Like

I still don’t get it. This thread talks about several answers that are wrong.
The lecture is wrong.
Can I please get a single set of answers that actually work with the latest version?
I tried putting:
{
“title” : “Rocky”,
“year” : “1976”,
“imdb” : “tt0075148”
}
What about the ID? Do I have to type it out? Or is it auto-generated?
I get the error with NO help on what is wrong.
Why is this the most difficult database to enter data?

Care to elaborate?

Share a screenshot.

Answered in post #15

1 Like

it also appears that if you click on the stack button on the inset panel and then back to the brackets button, an _id: field appears.

no, it is not autogenerated, it just gives an error and does nothing.