[SOLVED] Best way to extract first item in a collections' variables and put them in var?


#1

Hello and I’m sorry if this is too noobish to ask, I am still learning meteor!

Alright, so I have a collection, let’s say Books

export const Books= new Mongo.Collection('books');

Each book has an author name and a title, as their document variables. Just as an example.

If I wanted to extract the author of the first collection item/document only and put it inside a variable, what is the best way of doing it?
Psudo maybe something like this

   var firstCollectionAuthor = books.find({first document in collection.author});

I’m sure that’s wrong, as I tried it, that’s how much of a beginner I am :smiley: What is the best way of doing so? It does not seem straightforward to me as Java (i’m from a Java background).

Thank you for your time!


#2
var author = books.findOne().author

#3

What a legend!
Thanks heaps, I knew it was straight forward.


#4