insertOne and wrong Parameters - anyway returns "true" ... why?

It’s a bit confusing.
For testing purposes I’ve inserted the following WRONG insert-Command:

db.movies.insertOne({title: "Star Track II", year: 1982, imdb:"tt0084726" })
{
        "acknowledged" : true,
        "insertedId" : ObjectId("5e218dd916b5be234d9f5974")
}

You see, I insert it into db.movies, which not exists. It has to be db.moviesScratch to work.
But anyway, Mongo-DB returns true and an insertedId.

But where is the Dataset now inserted? I can’t find it anywhere. Doesn’t should MongoDB return an error here to give developers a chance to recognize this error?

Here’s an excerpt from the Insert documentation:


You will find the newly created collection and document in the movies collection.

Ok, I see now. It might be an Compass Bug?!
If I disconnect Compass and Re-Connect it, I see the “movies” collection with this one single entry.

Is this the way to do it? Why don’t Compass recognize themself that there is a movie-collection now?

If you insert data from the mongo shell into an existing db and collection, you need to click on the Refresh button on the top far right hand side in Compass.

If you insert data from the mongo shell into a new db and/or collection, you need to refresh the connection on the top left hand side in Compass.

1 Like