i try to get one element form array from Mongodb collection. I no need array with all data, i just need one element of it. So my db is like this:
_id: ObjectId("...")
arrayName :Array
: 'string1'
: 'string2'
...
Is there an option to get only one element of an array? for example the first one. This is my function, but this return all element of the array.
db.collection('collectionName')
.find()
.toArray()
.then((result) => {
response.data = result;
res.json(response);
})
I tried to use function findOne() instead of find(), but it does't work the way I want. thanks for help.