-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Broken in Mongoose 5.x.x #12
Comments
Same here, downgraded to make it work again :) |
@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? |
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. |
Correction, this[field] is undefined, where before there's an object with methods like addToSet. |
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 |
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 |
Getting the same error on the same line; using mongoose v5.0.11 and mongoose-keywords v0.3.2 Seems to work with |
@AshworthHub can you please provide some code samples? Considering that |
Note; Project was started off @diegohaz rest generator. Account Model 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);
}
};
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) |
Adding my case in here as well, both |
Thanks, I opened up a mongoose issue above ☝️ so we can track it in our milestones |
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. Looking at the call stack & in mongoose code:
so the doc is not yet populated with it's initial values. just checking for this[field] before addToSet fixes my problem... |
@nickhingston Would you mind sending a PR? |
Yes will do.
… On 4 Apr 2020, at 11:26, Haz ***@***.***> wrote:
@nickhingston Would you mind sending a PR?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Please can you merge the fix. Broke my code |
Hey,
I just tried mongoose-keywords with querymen (from the yeoman rest template) and upgraded all the packages; keywords seems to break with Mongoose 5.0.x, I'm afraid.
Offending line is:
this[field].addToSet(transform(value))
since this[field] is undefined.
Thanks!
The text was updated successfully, but these errors were encountered: