Question 41
How to connect to mongod instance and authenticate as root?
Question 42
You have a developers collection with the following document structure: { _id: 1, fname: 'John', lname: 'Smith', tech_stack: ['sql', 'git', 'python', 'linux', 'django', 'aws'] }, { _id: 2, fname: 'Michael', lname: 'Doe', tech_stack: [ 'git', 'python', 'sqlite', 'linux', 'flask' ] } Which of the following queries will return only the first three elements of the array in the tech_stack field?
Question 43
We have a movies collection with the following document structure: { _id: ObjectId("573a1390f29313caabcd6223"), genres: [ 'Comedy', 'Drama', 'Family' ], title: 'The Poor Little Rich Girl', released: ISODate("1917-03-05T00:00:00.000Z"), year: 1917, imdb: { rating: 6.9, votes: 884, id: 8443 } }, { _id: ObjectId("573a13e3f29313caabdc08a4"), genres: [ 'Horror', 'Thriller' ], title: 'Mary Loss of Soul', year: 2014, imdb: { rating: '', votes: '', id: 2904798 } } We need to use Aggregation Framework to calculate the following aggregates: -> average imdb rating -> minimum imdb rating -> maximum imdb rating Expected output: [ { _id: null, avg_rating: 6.6934040649367255, min_rating: 1.6, max_rating: 9.6 } ] Please note that some documents have "" (empty string) for the field "imdb.rating". Exclude these documents before aggregation. Which pipeline should you use?
Question 44
The users collection in the database is given. Which field will be the best candidate for an index in terms of cardinality?
Question 45
A collection called players contains the following documents: [ { _id: 1, user: 'Tom', scores: [ 23, 56, 3, 52, 62 ], bonus: 5 }, { _id: 2, user: 'Jane', scores: [ 42, 50, 10 ], bonus: 3 } ] You want to add additional fields to each document: -> total_score (sum of the scores Array) -> avg_score (average score in scores Array) Expected output: [ { _id: 1, user: 'Tom', scores: [ 23, 56, 3, 52, 62 ], bonus: 5, total_score: 196, avg_score: 39.2 }, { _id: 2, user: 'Jane', scores: [ 42, 50, 10 ], bonus: 3, total_score: 102, avg_score: 34 } ] Which query do you need to use?
