0

I have an abccollection collection whose documents look like:

{
    id:123
    focusPoint:89652.33
}

I want to retrieve all focusPoint values so that output looks like:

[89652.33, 89999.223, 99666.45, ...]

1 Answer 1

1

If you want to get a list without duplicates:

db.abccollection.distinct("focusPoint")

Otherwise, keeping duplicates:

db.abccollection.find({}, { _id: 0, focusPoint: 1 }).map((doc) => doc.focusPoint)

With that you will retrieve all the documents in the abccollection collection and project just the focusPoint field. The raw output of that query (before the map) will be an array of documents with a single field:

[{ focusPoint: 89652.33 }, { focusPoint: 89999.223 }, ...] 

If you don't want MongoDB to do the .map in MongoDB, you can also do it in your application.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.