question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using mongoose plugins doesn't seem to work

See original GitHub issue

I suppose to keep this Issue generic, I don’t seem to be able to add mongoose plugins to Keystone. I thought I could just access keystone.List('Post').model to get the native mongoose plugin and therefore specify in my model specification: Post.model.plugin(...);

But I am getting the following error:

TypeError: Object function model(doc, fields, skipId) {
    if (!(this instanceof model))
      return new model(doc, fields, skipId);
    Model.call(this, doc, fields, skipId);
  } has no method 'plugin'

Specifically I would love to use the plugin https://github.com/jamescarr/mongoosastic within keystone to provide some powerful search for the frontend. Unfortunately I don’t have any time right now to dig into the issue myself but will try at some point soon. But maybe @JedWatson you know immediately what the issue could be.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jeffreypriebecommented, Jan 23, 2016

For anyone finding this discussion wanting to setup mongoosastic, the bits are here (add mongoosastic to the schema before register), but to put it in code:

In your model (here named ‘Post’):

var mongoosastic = require('mongoosastic');

var Post = new keystone.List('Post', ...);

Post.add( {...} );
...
Post.schema.plugin(mongoosastic, { mongoosastic options here, like your host config });
Post.register();

More info on Mongoosastic options.

Easy. And agree with @Globegitter, ElasticSearch is awesome. Mongoosastic makes it so easy to get your data indexed.

0reactions
hari419commented, Jan 24, 2018

var event = new keystone.List(‘Event’); event.schema.plugin(timeZone,{ paths: [‘event_date’] }); i’m trying to use mongoose timezone plugin but when i’m trying to create a record for events keystone throwing an error Sorry, an error occurred loading the page (500) Cannot read property ‘numAsyncPres’ of undefined can anyone help me to solve this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using mongoose plugins doesn't seem to work #590 - GitHub
I suppose to keep this Issue generic, I don't seem to be able to add mongoose plugins to Keystone. I thought I could...
Read more >
Mongoose global plugins not working (ES6) - Stack Overflow
I got it working by up splitting plugins and models into separate files and created an index.js for importing all the plugins.
Read more >
Mongoose v6.8.1: FAQ
A. At its core, this issue stems from not connecting to MongoDB. You can use Mongoose before connecting to MongoDB, but you must...
Read more >
mongoose-autopopulate
Usage. The mongoose-autopopulate module exposes a single function that you can pass to Mongoose schema's plugin() function. const schema = new mongoose.
Read more >
Why does Mongoose remove the key when specified in the ...
... over why my data doesn't seem to be coming from the database. ... Can you also share the commands you use to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found