validateLab1.js doesn't exist

MongoDB Enterprise Cluster0-shard-0:PRIMARY> var count = db.movies.aggregate(pipeline).itcount();
MongoDB Enterprise Cluster0-shard-0:PRIMARY> print("Documents fetched by the pipeline (should be 23): " + count);
Documents fetched by the pipeline (should be 23): 23
MongoDB Enterprise Cluster0-shard-0:PRIMARY> load(‘validateLab1.js’)
2020-01-23T18:50:01.076+0000 E - [thread1] file [validateLab1.js] doesn’t exist
2020-01-23T18:50:01.076+0000 E QUERY [thread1] Error: error loading js file: validateLab1.js :
@(shell):1:1

The above error is gone.Now iam getting error when typing
validateLab1(pipeline)

MongoDB Enterprise Cluster0-shard-0:PRIMARY> var count =
db.movies.aggregate(pipeline).itcount();

MongoDB Enterprise Cluster0-shard-0:PRIMARY> print("Documents fetched by the pipeline (should be 23): " + count);

Documents fetched by the pipeline (should be 23): 23

MongoDB Enterprise Cluster0-shard-0:PRIMARY> validateLab1(pipeline)
2020-01-23T19:17:32.901+0000 E QUERY [thread1] ReferenceError: validateLab1 is not defined :
@(shell):1:1

Hi @SUJANA_42894,

Please ensure that you navigate to the directory where you have stored validateLab1.js in the terminal. Then run the mongo instance using the connection string provided.

You should be able to load validators then.

Please let me know, if you have any questions.

Thanks,
Sonali

Iam able to load validateLab1.js using load(‘validateLab1.js’) and getting output as true.

But when iam running validateLab1(pipeline),iam getting error like this

MongoDB Enterprise Cluster0-shard-0:PRIMARY> validateLab1(pipeline)
2020-01-24T14:37:26.086+0000 E QUERY [thread1] ReferenceError: validateLab1 is not defined :
@(shell):1:1

Hi @SUJANA_42894,

Got it!!

It looks like after you have run the command: load('validateLab1.js'), you exited from the mongo shell. In that case, your pipeline variable no longer exists.

I would recommend you to again create the pipeline and run the following commands:

var pipeline = [ { } ]
db.movies.aggregate(pipeline).itcount()
load(‘validateLab1.js’)
validateLab1(pipeline)

You should get the answer after that.

Please let me know, if you have any questions.

Thanks,
Sonali

I did not exit from momgo shell when running validateLab1(pipeline)

MongoDB Enterprise Cluster0-shard-0:PRIMARY> var pipeline = [ { $match : { $and : [ { “imdb.rating” : { $gte : 7 }}, { “genres” : { $nin :[ “Crime”, “Horror” ]} }, { “rated” : { $in : [ “PG”, “G” ]} }, { “languages” : { $all : [ “English”, “Japanese” ]} } ]} } ];
MongoDB Enterprise Cluster0-shard-0:PRIMARY> load(‘validateLab1.js’)
true
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.aggregate(pipeline).itcount();
23
MongoDB Enterprise Cluster0-shard-0:PRIMARY> validateLab1(pipeline)
2020-01-24T15:24:57.275+0000 E QUERY [thread1] ReferenceError: validateLab1 is not defined :
@(shell):1:1

I resolved issue,by updating mongodb