Questions Regarding MongoDB C100DBA Associate Exam

I’m currently preparing for the MongoDB Associate DBA (C100DBA) exam. I’m doing practice and am stuck with some problems. A little help would be appreciated.

I have the following document with collections named ‘c’:

db.c.find()

{ “_id” : 12, b : [ 3, 5, 7, 2, 1, -4, 3, 12 ] }

How do I return only the first five elements of the array in the ‘b’ field?

I’m using this db.c.find( { b : [ 0 , 5 ] > ) which is not working.

Hi @johnm52,

Welcome to Katalon Community! :wave:

As this is a community for Katalon Platform users, we’re not sure whether you’d receive the support you need here. Nevertheless, we’ll keep your topic opened for one week and if it hasn’t been answered by then, we’ll close it. Thanks :+1:

The answer should be in the MongoDB doc.
You may need an aggregation expresion in the projection, e.g:

2 Likes

OK, thank you for clarifying what is this community for.

Thanks for sharing the doc. Already have gone through it but could not find the solution.

well, i cannot help you more.
i don’t have a mongodb setup at my hands to replicate your usecase.
and, in the end, it is you attempting to be certified, so do your homeworks.

hint: even if you may be tempted to ask on stackoverflow (which is by far a better resource to look/ask for such solutions) do not mention “i wanna be certified”
RTFM will be the standard answer and the most honest!

cheers!

@albert.vu kindly close it.

You are missing the $slice projection operator. Use it to specify the number of elements in the array to return in the query result.

db.c.find( { > , { b : { $slice : [ 0 , 5 ] } } )

I’d recommend this source https://www.examskit.com as I found it helpful during my exam preparation. Here you can find these types of questions with answers.

3 Likes

Great, it worked. Thank you @SJames.

Got it @anon46315158 thanks for the advice.

This topic was automatically closed after 7 days. New replies are no longer allowed.