First, thanks for the hard work on nuxt content. Very cool.
Playing around with some sample data like-a-so:
"Year", "Score", "Title"
1968, 86, "Greetings"
1970, 17, "Bloody Mama"
1970, 73, "Hi, Mom!"
1971, 40, "Born to Win"
1973, 98, "Mean Streets"
1973, 88, "Bang the Drum Slowly"
1974, 97, "The Godfather, Part II"
1976, 41, "The Last Tycoon"
1976, 99, "Taxi Driver"
In a CSV I'm having a tough time using sortBy or only. Example ("deniro" is the csv)
const deniroMovies = await $content('deniro')
.sortBy('Title')
.fetch()
Is that not possible yet?
Hi @dolbex,
The sortBy method is used to sort documents in a directory.
When using CSV, the lines are transformed into an array and stored in a body variable inside a single document. Like MongoDB, you cannot sort an array inside of a document.
You could perform a sort with Lodash for example:
const { body } = await $content('deniro').fetch()
return {
movies: sortBy(body, 'title')
}
@benjamincanac
Right on, and that's exactly what I did in my little test. I will say though, coming in cold, it's a little confusing seeing the comparisons to mongo, the cool queries on the document directories and then it not working in the following scenarios:
I'm not even implying that it _should_ work for those two scenarios - it's just where I got a little head scratchy while working with hit for the first time.
I'm looking to see how I can use this for a client project that is a small CMS. Definitely looking forward to working with it.
@dolbex
To detail the comparison with MongoDB, a directory is like a collection and a file is a document inside that collection.
As far as JSON arrays and CSV, the only way would be to flatten them inside the collection. However documents would have the same slug so it wouldn't be possible to fetch them anymore.