doc.pushToAlgolia is not a function
- Dominant language
- JavaScript
- Stars
- 61
- Forks
- 12
- PR merge metrics
- No merged PRs in 30d
Description
It throws this error when I run
`User.syncWithAlgolia().then((r) => console.log(r)).catch((err) => console.log(err));`
```
(node:3160) DeprecationWarning: collection.update is deprecated. Use updateOne, updateMany, or bulkWrite instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
POST /graphql 200 891.404 ms - 12130
TypeError: doc.pushToAlgolia is not a function
at /Users/damiisdandy/Development/jetronmall/api/node_modules/mongoolia/dist/algolia-mongoose-model.js:44:22
at Array.map ()
at /Users/damiisdandy/Development/jetronmall/api/node_modules/mongoolia/dist/algolia-mongoose-model.js:43:32
at Generator.next ()
at step (/Users/damiisdandy/Development/jetronmall/api/node_modules/mongoolia/dist/algolia-mongoose-model.js:13:191)
at /Users/damiisdandy/Development/jetronmall/api/node_modules/mongoolia/dist/algolia-mongoose-model.js:13:361
at processTicksAndRejections (node:internal/process/task_queues:96:5)
```
This is my model file
```
import { Schema, model } from 'mongoose';
import bcrypt from 'bcryptjs';
// @ts-ignore
import mongoolia from 'mongoolia';
import { algoliaConfig, PASSWORD_SALT_ROUNDS } from '../../config';
const User = new Schema(
{
firstName: { type: String, algoliaIndex: true },
lastName: { type: String, algoliaIndex: true },
phone: String,
email: { type: String, algoliaIndex: true },
password: String,
isConfirmed: {
type: Boolean,
default: false,
},
roles: [{ type: Schema.Types.ObjectId, ref: 'Role' }],
},
{ timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' } }
);
User.pre('save', async function (next) {
try {
if (!this.isModified('password')) return next();
// @ts-ignore
this.password = await bcrypt.hash(this.password, PASSWORD_SALT_ROUNDS);
next();
} catch (err: any) {
next(err);
}
});
User.plugin(mongoolia, {
...algoliaConfig,
indexName: 'users'
});
User.methods.validatePassword = async function (data) {
// @ts-ignore
return bcrypt.compare(data, this.password);
};
export default model('User', User);
```
but `User.algoliaSearch` works fine
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the model file shown in the issue and its mongoolia plugin setup; reproduce User.syncWithAlgolia() and trace the pushToAlgolia call reported in mongoolia/dist/algolia-mongoose-model.js. Done means syncWithAlgolia completes without the TypeError while User.algoliaSearch continues to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- database, search
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100