Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
428 views
in Technique[技术] by (71.8m points)

node.js - Sync MongoDB with Algolia Search Nodejs

Trying to Sync my MongoDB collections using mongoose-algolia package (https://www.npmjs.com/package/mongoose-algolia)

My schema

const ProjectSchema = new Schema(
  {
    name: {
      type: String,
      trim: true,
      required: [true, 'Name is required!'],
    },
    description: {
      type: String,
      required: [true, 'Description is required!'],
    }
  },
  { timestamps: true },
);

And this is How I use the mongoose library according to the docs

ProjectSchema.plugin(mongooseAlgolia, {
  appId: process.env.ALGOLIA_APPLICATION_ID,
  apiKey: process.env.ALGOLIA_ADMIN_API_KEY,
  indexName: 'project-search',
  selector: 'name description',
});

And finally I am using it as such

let Project = mongoose.model('Project', ProjectSchema)
 
Project.SyncToAlgolia()

I been getting this error

TypeError: Project.SyncToAlgolia is not a function

Am I doing anything wrong? Looking at the documentation, this is exactly how they used it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...