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.
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
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!
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.