replaceOne() function

Hi,

I tried working on the handout provided with respect to replaceOne() function. I tried executing “push” function. Getting the error mentioned below. Please guide

MongoDB Enterprise Cluster0-shard-0:PRIMARY> doc1.genre.push(“TV Series”)
2019-05-04T19:30:01.074+0530 E QUERY [js] TypeError: doc1.genre.push is not a function :
@(shell):1:1

Please check the field genre.Should be genres
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movieDetails.findOne()

Thanks. I got confused between Atlas Course Cluster and our sandbox cluster. One had “genre” as its field name and other “genres”. Thanks for pointing it out.

I have the same problem.

doc2 returns the document from findone().
doc2.genre shows the correct values for genre from the same findone set.
However when I try to push it fails

MongoDB Enterprise Cluster0-shard-0:PRIMARY> doc2
{
“_id” : ObjectId(“58c59c6a99d4ee0af9e0c325”),
“title” : “Carmencita”,
“year” : 1894,
“imdbId” : “tt0000001”,
“mpaaRating” : “NOT RATED”,
“genre” : “Documentary, Short”,
“viewerRating” : 5.9,
“viewerVotes” : 1032,
“runtime” : 1,
“director” : “William K.L. Dickson”,
“cast” : [
“Carmencita”
],
“plot” : “Performing on what looks like a small wooden stage, wearing a dress with a hoop skirt and white high-heeled pumps, Carmencita does a dance with kicks and twirls, a smile always on her face.”
}

MongoDB Enterprise Cluster0-shard-0:PRIMARY> doc2.genre
Documentary, Short

MongoDB Enterprise Cluster0-shard-0:PRIMARY> doc2.genre.push(“TV Series”);
2019-05-21T22:41:21.237-0400 E QUERY [js] TypeError: doc2.genre.push is not a function :
@(shell):1:1
MongoDB Enterprise Cluster0-shard-0:PRIMARY>

Any helps?

Hi @Syamantak_98200,

Here the genre field is String and not array. You can use $push operator only to add elements in the array.

Please let me know, if you have any other doubts.

Thanks,
Sonali

Thanks Sonali for correcting me. I was connecting to Class cluster and got confused

Hi!
I have such problem!
“doc.genres” gives answer: [ “Adventure”, “Drama”, “Sci-Fi” ]
BUT next “doc.genres.push(“asdasd”)” gives exception: 2019-06-07T09:06:50.442+0000 E QUERY [js] TypeError: doc.genres.push is not a function :
@(shell):1:1
What’s wrong? Could you help me?

Hi @Vitali_04196,

Please ensure that you are connected to the Sandbox Cluster video.movieDetails collection.

Also, make sure that you type the following command in the mongo shell and do not copy paste.

If you still face this issue, please share the screenshot of the command that you have run and the error.

Thanks,
Sonali

Hi @Sonali_Mamgain.
Thank you for answer!
Now it’s work.
But i did the same thing.
May something was wrong with cluster.