Mounted mongodb find? (SOLVED)

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.

Unavngivet

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?

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?

prefers in mongodb

{
    "_id" : "7PyiAhv7hhEvwF5Nz",
    "userid" : "Xuzw8ereCmsWLHb6v",
    "done" : "0",
    "Env" : [ 
        "dust"
    ]
}

Howto define Meteor?

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