Learn how to create a Vue.js component to list all entires from a mongodb collection
Write a vue.js component that lists all entries from a collection in a mongodb database.
vue Copy code
<template>
<div>
<ul>
<li v-for="entry in entries" :key="entry._id">
{{ entry.name }}
</li>
</ul>
</div>
</template>
<script>
import { databaseCollection } from 'yourdatabase.js'
export default {
name: 'CollectionList',
data () {
return {
entries: []
}
},
created: function() {
databaseCollection.find({}).toArray((err, entries) =>{
this.entries = entries
})
}
}