JavaScript Is there a way to get the model name from a mongoose model instance? there she goes model name,there she goes song model

I´m using mongoose and I need to find a model name from a model instance.

In one part of the code I have:

 const schema = new mongoose.Schema({
        name: {
            type: String,
            required: true
        },
        phone: {
            type: String,
            required: true
        }
    }

const schema = new mongoose.Schema('MyData', schema);

let instance = new this({
      name: 'Pete',
      phone: '123'
});

Ths instance variable is passed around in my code. Later I need to find out instance name, but I´m no sure if there is a way to do it, something like:

let instanceName = getInstanceName(instance); <== Expects 'MyData' to be returned

Is that possible using mongoose ?

Answer:1

The name of the model can be accessed using this instance.constructor.modelName.

Answer:2

Im using codeigniter to load a view. This view has a button to open a modal and in this modal i must load a method from another controller. To do this, i'm using ajax passing data by POST. This is my ...

Im using codeigniter to load a view. This view has a button to open a modal and in this modal i must load a method from another controller. To do this, i'm using ajax passing data by POST. This is my ...

  1. jquery ajax cross domain
  2. jquery.ajax-cross-origin.min.js
  3. jquery ajax cross domain access-control-allow-origin
  4. jquery ajax cross origin
  5. jquery ajax cross-origin request blocked
  6. jquery ajax cross domain post
  7. jquery ajax cross domain request example
  8. jquery ajax redirect to another page
  9. jquery ajax redirect to another page with data
  10. jquery ajax cross domain example

I'm trying to sort the JSON by release date, by random, by alphabetical order or by popularity. I'm not sure if the answer is on here, I checked and I can't seem to figure out if it's for me. My ...

I'm trying to sort the JSON by release date, by random, by alphabetical order or by popularity. I'm not sure if the answer is on here, I checked and I can't seem to figure out if it's for me. My ...

I try to create a new pieces page, kind of a blog style in apostrophe cms. I have trainings, trainings-widgets and trainings-pages folders. I registered them all in app.js; pieces by themselves and ...

I try to create a new pieces page, kind of a blog style in apostrophe cms. I have trainings, trainings-widgets and trainings-pages folders. I registered them all in app.js; pieces by themselves and ...

  1. apostrophe pieces pages

I am passing a state as props in child component, but child is updating previous props to its state. For example: I am passing state = a, then state is updated to state = b. Child will update it as ...

I am passing a state as props in child component, but child is updating previous props to its state. For example: I am passing state = a, then state is updated to state = b. Child will update it as ...