Giter VIP home page Giter VIP logo

Comments (16)

diegohaz avatar diegohaz commented on September 27, 2024 2

@awojtczyk Yes, but I still didn't try Mongoose v5

I can take a look on this by Sunday.

Would you guys like to investigate a solution in the meanwhile?

from mongoose-keywords.

diegohaz avatar diegohaz commented on September 27, 2024 1

After some hours of suffering, I still can't find a solution. It seems to be a bug in Mongoose, but I'm not sure. Docs aren't clear about it either.

Created an issue there: Automattic/mongoose#6155

from mongoose-keywords.

awojtczyk avatar awojtczyk commented on September 27, 2024

Same here, downgraded to make it work again :)
@diegohaz is this repo being maintained?

from mongoose-keywords.

zaubara avatar zaubara commented on September 27, 2024

Awesome!

I wasn't able to find a solution until yet; from what I can tell, it's different in v5 when the parsePath methods are called; seemingly every api call now, ie. "_this" is now undefined.
Maybe there's something on https://github.com/Automattic/mongoose/blob/master/migrating_to_5.md that helps.

from mongoose-keywords.

zaubara avatar zaubara commented on September 27, 2024

Correction, this[field] is undefined, where before there's an object with methods like addToSet.

from mongoose-keywords.

diegohaz avatar diegohaz commented on September 27, 2024

It seems the bug was fixed on mongoose, and will be shipped in v5.0.10. Could you guys try it when it gets released?

I'm going to close the issue right now, but I can reopen if the issue remains after v5.0.10

from mongoose-keywords.

peteashworth avatar peteashworth commented on September 27, 2024

Getting the same error on the same line; using mongoose v5.0.11 and mongoose-keywords v0.3.2

Seems to work with findById but findOne or find fails.

from mongoose-keywords.

vkarpov15 avatar vkarpov15 commented on September 27, 2024

@AshworthHub can you please provide some code samples? Considering that findById() is just a thin wrapper for findOne() it sounds very strange that findById() works but not findOne()

from mongoose-keywords.

peteashworth avatar peteashworth commented on September 27, 2024

Note; Project was started off @diegohaz rest generator.

Account Model
accountSchema.plugin(mongooseKeywords, { paths: ['name', 'tags'] });

export const getShop = ({ params, query }, res, next) => {
  console.log('get shop');
  const accountId = get(params, 'accountId');
  const shopName = get(query, 'shop');
  if (accountId) {
    console.log('accountId', accountId);
    Account.findById(accountId)
      .then(notFound(res))
      .then(account => account.view())
      .then(success(res))
      .catch(next);
  } else if (shopName) {
    console.log('shopName', shopName);
    Account.findOne({ name: shopName })
      .then(notFound(res))
      .then(account => account.view())
      .then(success(res))
      .catch(next);
  }
};

/58929ff994f0e70007f9da33 works as it will use the accountId section.

?shop=testing gives the following error

TypeError: Cannot read property 'addToSet' of undefined
    at parsePath (/Users/peterashworth/Projects/salon-api/node_modules/mongoose-keywords/dist/index.js:60:24)
    at model.Query.<anonymous> (/Users/peterashworth/Projects/salon-api/node_modules/mongoose-keywords/dist/index.js:69:9)
    at SchemaString.SchemaType._applySetters (/Users/peterashworth/Projects/salon-api/node_modules/mongoose/lib/schematype.js:693:22)
    at SchemaString.SchemaType.applySetters (/Users/peterashworth/Projects/salon-api/node_modules/mongoose/lib/schematype.js:717:16)
    at SchemaString.SchemaType._castForQuery (/Users/peterashworth/Projects/salon-api/node_modules/mongoose/lib/schematype.js:1095:15)
    at SchemaString.castForQuery (/Users/peterashworth/Projects/salon-api/node_modules/mongoose/lib/schema/string.js:515:15)
    at SchemaString.SchemaType.castForQueryWrapper (/Users/peterashworth/Projects/salon-api/node_modules/mongoose/lib/schematype.js:1064:15)
    at cast (/Users/peterashworth/Projects/salon-api/node_modules/mongoose/lib/cast.js:300:32)
    at model.Query.Query.cast (/Users/peterashworth/Projects/salon-api/node_modules/mongoose/lib/query.js:3198:12)
    at model.Query.Query._castConditions (/Users/peterashworth/Projects/salon-api/node_modules/mongoose/lib/query.js:1278:10)
    at model.Query.Query._findOne (/Users/peterashworth/Projects/salon-api/node_modules/mongoose/lib/query.js:1494:8)
    at /Users/peterashworth/Projects/salon-api/node_modules/kareem/index.js:276:8
    at /Users/peterashworth/Projects/salon-api/node_modules/kareem/index.js:77:15
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)

from mongoose-keywords.

pthieu avatar pthieu commented on September 27, 2024

Adding my case in here as well, both .find() and .findOne() does not work.
if i remove the line userSchema.plugin(mongooseKeywords, { paths: [...]}) from my schema file, it works

from mongoose-keywords.

vkarpov15 avatar vkarpov15 commented on September 27, 2024

Thanks, I opened up a mongoose issue above ☝️ so we can track it in our milestones

from mongoose-keywords.

diegohaz avatar diegohaz commented on September 27, 2024

Released v0.4.0 with @lineus's changes in #13. Hopefully, now it fully supports mongoose v5 (at least, all tests are passing).

Thank you so much for the time you guys invested on this.

from mongoose-keywords.

nickhingston avatar nickhingston commented on September 27, 2024

I'm not convinced this is fixed, it seems that Model.create causes the same problem with mongoose 5.9.7

seems this[field] is undefined on line 35 of src/index.js.
so:
this[field].addToSet(transform(value))
crashes

Looking at the call stack & in mongoose code:

 // By default, defaults get applied **before** setting initial values
    // Re: gh-6155
    $__applyDefaults(this, fields, skipId, exclude, hasIncludedChildren, true, {

so the doc is not yet populated with it's initial values.

just checking for this[field] before addToSet fixes my problem...

from mongoose-keywords.

diegohaz avatar diegohaz commented on September 27, 2024

@nickhingston Would you mind sending a PR?

from mongoose-keywords.

nickhingston avatar nickhingston commented on September 27, 2024

from mongoose-keywords.

dagenius007 avatar dagenius007 commented on September 27, 2024

Please can you merge the fix. Broke my code

from mongoose-keywords.

Related Issues (11)

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.