Giter VIP home page Giter VIP logo

Comments (6)

mihaiserban avatar mihaiserban commented on May 18, 2024 1

For overwrite error the following example helped me alot.
// OverwriteModelError: Cannot overwrite User model once compiled.

https://github.com/LanmeijingLucky/micro-Mongoose-example

const initColl = () => {
  if(mongoose.models.Log) {
    return mongoose.model('Log')
  }
  else {
    return mongoose.model('Log', LogSchema);
  }
}
module.exports = initColl();

from micro-dev.

williamli avatar williamli commented on May 18, 2024 1

I use something like


const mongoose = require('mongoose');

var schema = new mongoose.Schema({
  _id: mongoose.Schema.Types.ObjectId,
  title: Array,
  slug: String,
  fields: Array,
  definitions: Array,
  meta: {
    createdAt: Date,
    updatedAt: Date,
    publishAt: Date,
    unpublishAt: Date
  }
});

const getModel = () => {
  if (mongoose.models.Page) {
    return mongoose.model('Page')
  } else {
    return mongoose.model('Page', schema, 'Pages');
  }
}

module.exports = getModel()


const Page = require('./dbSchema.js');

Page.find((err, data) => {...

from micro-dev.

tungv avatar tungv commented on May 18, 2024

You may want to ignore your schema files so it will not reload them.

Assuming you put schema files in <project_dir>/src/models please run micro dev with -i **/src/models. This will neither watch those files nor rerun them

from micro-dev.

sholtomaud avatar sholtomaud commented on May 18, 2024

Thanks for the quick response! :)

I'm afraid that doesn't seem to work, I've tried a few variants, and I have models in the src folder

micro-dev --ignore src/models/*.js index.js 
micro-dev --ignore src/models/ index.js 
micro-dev -i ./src/models index.js 

I think the -i switch isn't registered as it falls over saying that "File changed: src/models/user.js", which it did.

from micro-dev.

tungv avatar tungv commented on May 18, 2024

since -i receive a pattern matching absolute paths, so you have to start with **.

Btw, if you really want to change the content of src/models/user.js, I don't think micro-dev hot reload model would work.

from micro-dev.

sholtomaud avatar sholtomaud commented on May 18, 2024

brilliant! 👍

from micro-dev.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.