search: correctly register/export schema/models for mongoMeili

This commit is contained in:
Daniel Avila 2023-03-22 01:31:01 -04:00
parent 8be19f9982
commit a5cf2f9148
6 changed files with 231 additions and 53 deletions

View file

@ -1,5 +1,6 @@
const mongoose = require('mongoose');
module.exports = mongoose.Schema(
const mongoMeili = require('../plugins/mongoMeili');
const convoSchema = mongoose.Schema(
{
conversationId: {
type: String,
@ -50,4 +51,15 @@ module.exports = mongoose.Schema(
messages: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Message' }]
},
{ timestamps: true }
);
);
convoSchema.plugin(mongoMeili, {
host: process.env.MEILI_HOST,
apiKey: process.env.MEILI_KEY,
indexName: 'convos', // Will get created automatically if it doesn't exist already
primaryKey: 'conversationId'
});
const Conversation = mongoose.models.Conversation || mongoose.model('Conversation', convoSchema);
module.exports = Conversation;