thorus
1
I have a edit page with some checkboxes,
I use Meteor, vue and Vuetify
Se under setTimeout there is a line I dont know howto code correct. It works with the hardcoded db content
new Vue({
el: '#app',
/*
export default {
meteor: {
selected() {
DATA FROM DB
}
}
},
*/
data () {
return {
selected: []
/*
Is this possible?
selected {DATA ARRAY FROM DB}
*/
}
},
mounted () {
setTimeout(() => {
**DONT WORK, howto fix? ->** const mongoData = { return Meteor.prefers.find({"_id": Meteor.userId() } );
/*
"_id" : "dKyqdjJm5rPdpfg88",
"userid" : "Xuzw8ereCmsWLHb6v",
"Selected" : [
"dust"
] */
}
this.checkenvirometals = mongoData.Selected
}, 3000)
},
})
find
returns a cursor. You probably want findOne
.
Missed that.
You’re trying to define an object with no property name (or, in ES6 an object with an illegal inferred property name).
I think you just need const mongoData = Meteor.prefers.findOne({"_id": Meteor.userId()});
I am assuming that Meteor.prefers
is a collection reference?
thorus
5
mounted () {
setTimeout(() => {
const mongoData = Meteor.prefers.findOne({"_id": Meteor.userId()});
/*
"_id" : "dKyqdjJm5rPdpfg88",
"userid" : "Xuzw8ereCmsWLHb6v",
"Env" : [
"dust"
] */
this.checkenvirometals = mongoData.Env
}, 3000)
},
Give me this error:
Uncaught TypeError: Cannot read property ‘findOne’ of undefined
So, what is Meteor.prefers
?
Is Meteor
defined?
thorus
7
prefers in mongodb
{
"_id" : "7PyiAhv7hhEvwF5Nz",
"userid" : "Xuzw8ereCmsWLHb6v",
"done" : "0",
"Env" : [
"dust"
]
}
Howto define Meteor?
thorus
8
It worked with:
export default {
meteor: {
mounted () {
const mongoData = Prefers.findOne({userid: Meteor.userId()});
this.checkenvirometals = mongoData.Env;
console.log(this.checkenvirometals);
},
},
Thanks for your help
1 Like