Giter VIP home page Giter VIP logo

Comments (7)

VassilisPallas avatar VassilisPallas commented on May 13, 2024

According to the documentation you need to use keys for nested attributes.
https://github.com/VassilisPallas/mongoose-fuzzy-searching#object-field

from mongoose-fuzzy-searching.

egonzal93 avatar egonzal93 commented on May 13, 2024

I used keys:

const mongoose = require('mongoose');
const mongoose_fuzzy_searching = require('mongoose-fuzzy-searching');

const taskSchema = new mongoose.Schema({
name: {
type: String,
required: true
},
info: {
name1: String,
title: String,
version: String,
description: String
},
completed: {
type: Boolean,
required: true
},
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
}
}, {
timestamps: true
});

taskSchema.plugin( mongoose_fuzzy_searching, {
fields: [{
name: 'info',
keys: [
'name1',
'title',
'version',
'description'
]
}]
}
);

module.exports = mongoose.model('Task', taskSchema);

Saved it:

addNewTask = async () => {
const debug = require('debug')('add_new_task');
const input = {
name: taskTitle,
info: {
name1: "Army1 Ants1",
title: "Army1 Ants2",
version: "Army1 Ants3",
description: "Army1 Ants4"
},
completed: false
};
try {
const user = await User.findOne({email: taskEmail});
debug(user ${JSON.stringify(user, null,2)});
const task = new Task({...input, user: user.id});
const result = await task.save();
user.tasks.push(result.id);
await user.save();
debug(result=${JSON.stringify(result, null,2)});
return result;
} catch (error) {
console.log(error);
}

but still anagrams are not getting saved to mongo:

Mongoose: tasks.insertOne({ _id: ObjectId("5fb326440deaa5357845fa8b"), name: 'Army1 of Ants', info: { name1: 'Army1 Ants1', title: 'Army1 Ants2', version: 'Army1 Ants3', description: 'Army1 Ants4' }, completed: false, user: ObjectId("5f91caa051fa0512993e9326"), info_fuzzy: [ { name1_fuzzy: [ 'y1', 'my', 'rm', 'ar', 'my1', 'rmy', 'arm', 'rmy1', 'army', 'army1', 's1', 'ts', 'nt', 'an', 'ts1', 'nts', 'ant', 'nts1', 'ants', 'ants1', 'army1 ants1' ], title_fuzzy: [ 'y1', 'my', 'rm', 'ar', 'my1', 'rmy', 'arm', 'rmy1', 'army', 'army1', 's2', 'ts', 'nt', 'an', 'ts2', 'nts', 'ant', 'nts2', 'ants', 'ants2', 'army1 ants2' ], version_fuzzy: [ 'y1', 'my', 'rm', 'ar', 'my1', 'rmy', 'arm', 'rmy1', 'army', 'army1', 's3', 'ts', 'nt', 'an', 'ts3', 'nts', 'ant', 'nts3', 'ants', 'ants3', 'army1 ants3' ], description_fuzzy: [ 'y1', 'my', 'rm', 'ar', 'my1', 'rmy', 'arm', 'rmy1', 'army', 'army1', 's4', 'ts', 'nt', 'an', 'ts4', 'nts', 'ant', 'nts4', 'ants', 'ants4', 'army1 ants4' ] } ], createdAt: new Date("Tue, 17 Nov 2020 01:24:20 GMT"), updatedAt: new Date("Tue, 17 Nov 2020 01:24:20 GMT"), __v: 0 }, { session: null })
Mongoose: users.updateOne({ _id: ObjectId("5f91caa051fa0512993e9326") }, { '$push': { tasks: { '$each': [ ObjectId("5fb326440deaa5357845fa8b") ] } }, '$set': { updatedAt: new Date("Tue, 17 Nov 2020 01:24:20 GMT") }, '$inc': { __v: 1 } }, { session: undefined })
add_new_task result={
add_new_task "_id": "5fb326440deaa5357845fa8b",
add_new_task "name": "Army1 of Ants",
add_new_task "info": {
add_new_task "name1": "Army1 Ants1",
add_new_task "title": "Army1 Ants2",
add_new_task "version": "Army1 Ants3",
add_new_task "description": "Army1 Ants4"
add_new_task },
add_new_task "completed": false,
add_new_task "user": "5f91caa051fa0512993e9326",
add_new_task "createdAt": "2020-11-17T01:24:20.268Z",
add_new_task "updatedAt": "2020-11-17T01:24:20.268Z",
add_new_task "__v": 0

from mongoose-fuzzy-searching.

egonzal93 avatar egonzal93 commented on May 13, 2024

NVM, it worked this time: Thanks for the response. Good night.

{"_id":{"$oid":"5fb3286e8b01a735eb82f5dc"},"name":"Army1 of Ants","info":{"name1":"Army1 Ants1","title":"Army1 Ants2","version":"Army1 Ants3","description":"Army1 Ants4"},"completed":false,"user":{"$oid":"5f91caa051fa0512993e9326"},"info_fuzzy":[{"name1_fuzzy":["y1","my","rm","ar","my1","rmy","arm","rmy1","army","army1","s1","ts","nt","an","ts1","nts","ant","nts1","ants","ants1","army1 ants1"],"title_fuzzy":["y1","my","rm","ar","my1","rmy","arm","rmy1","army","army1","s2","ts","nt","an","ts2","nts","ant","nts2","ants","ants2","army1 ants2"],"version_fuzzy":["y1","my","rm","ar","my1","rmy","arm","rmy1","army","army1","s3","ts","nt","an","ts3","nts","ant","nts3","ants","ants3","army1 ants3"],"description_fuzzy":["y1","my","rm","ar","my1","rmy","arm","rmy1","army","army1","s4","ts","nt","an","ts4","nts","ant","nts4","ants","ants4","army1 ants4"]}],"createdAt":{"$date":"2020-11-17T01:33:34.923Z"},"updatedAt":{"$date":"2020-11-17T01:33:34.923Z"},"__v":0}

from mongoose-fuzzy-searching.

egonzal93 avatar egonzal93 commented on May 13, 2024

It looks like the old key indexes needs to be dropped when you change keys.

from mongoose-fuzzy-searching.

VassilisPallas avatar VassilisPallas commented on May 13, 2024

Yes indeed. I'm currently working on deleting the indexes every time.

from mongoose-fuzzy-searching.

egonzal93 avatar egonzal93 commented on May 13, 2024

Do you know when you plan on releasing an update? Should the index expire so that it can be rebuilt?

from mongoose-fuzzy-searching.

VassilisPallas avatar VassilisPallas commented on May 13, 2024

I think we can expire only date indexes. The ideal scenario is every time you restart your application to delete manually the indexes. I will try to delete them when the plugin is initialized.
However, I don't know if this is possible

from mongoose-fuzzy-searching.

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.