Comments (16)
@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.
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.
Same here, downgraded to make it work again :)
@diegohaz is this repo being maintained?
from mongoose-keywords.
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.
Correction, this[field] is undefined, where before there's an object with methods like addToSet.
from mongoose-keywords.
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.
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.
@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.
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.
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.
Thanks, I opened up a mongoose issue above
from mongoose-keywords.
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.
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.
@nickhingston Would you mind sending a PR?
from mongoose-keywords.
from mongoose-keywords.
Please can you merge the fix. Broke my code
from mongoose-keywords.
Related Issues (11)
- Require default
- An in-range update of eslint is breaking the build 🚨 HOT 2
- Generate keywords from an array of object HOT 3
- Combine custom keywords path options and nested models
- Generate keywords from existing documents HOT 3
- Multiple keywords from one path
- Updating nested keywords only works when we save the object with the nested object populated with keywords
- Support array refs
- Lets say I want to add a query with querymen... HOT 5
- An in-range update of babel-eslint is breaking the build 🚨
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongoose-keywords.