{"action":"opened","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/6097","repository_url":"https://api.github.com/repos/Automattic/mongoose","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/6097/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/6097/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/6097/events","html_url":"https://github.com/Automattic/mongoose/issues/6097","id":294674081,"number":6097,"title":"Mongoose 5.0.0 broken where behavior","user":{"login":"nodkz","id":1946920,"avatar_url":"https://avatars2.githubusercontent.com/u/1946920?v=4","gravatar_id":"","url":"https://api.github.com/users/nodkz","html_url":"https://github.com/nodkz","followers_url":"https://api.github.com/users/nodkz/followers","following_url":"https://api.github.com/users/nodkz/following{/other_user}","gists_url":"https://api.github.com/users/nodkz/gists{/gist_id}","starred_url":"https://api.github.com/users/nodkz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodkz/subscriptions","organizations_url":"https://api.github.com/users/nodkz/orgs","repos_url":"https://api.github.com/users/nodkz/repos","events_url":"https://api.github.com/users/nodkz/events{/privacy}","received_events_url":"https://api.github.com/users/nodkz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-06T08:42:00Z","updated_at":"2018-02-06T08:42:00Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Example code:\r\n```js\r\n// default query\r\nconst userQuery = User.where({ status: 'approved' }); \r\n\r\n// some logic, which generates additional criterias or change default\r\nconst someFilter = { \r\n  status: { $ne: 'delayed' },\r\n};\r\n\r\n// merging criterias and query execution\r\nconst data = await userQuery.where(someFilter).exec();\r\n```\r\n\r\n**With Mongoose 4 it works without problem**\r\nIt generates/merge following criteria: `{ status: { $ne: 'delayed' } }`.\r\n\r\n**With Mongoose 5.0.3 it fails with error** \r\n<details>\r\n  <summary>`Cannot create property '$ne' on string 'approved'`</summary>\r\n\r\n  - utils.js:320 merge\r\n    [npm_ram_disk]/[mongoose]/lib/utils.js:320:15\r\n  - utils.js:322 Object.merge\r\n    [npm_ram_disk]/[mongoose]/lib/utils.js:322:7\r\n  - query.js:1417 model.Query.Query.merge\r\n    [npm_ram_disk]/[mongoose]/lib/query.js:1417:9\r\n  - mquery.js:276 model.Query.Query.where\r\n    [npm_ram_disk]/[mquery]/lib/mquery.js:276:17\r\n  - filter.js:151 filterHelper\r\n    [npm_ram_disk]/[graphql-compose-mongoose]/lib/resolvers/helpers/filter.js:151:47\r\n  - count.js:40 resolve\r\n    [npm_ram_disk]/[graphql-compose-mongoose]/lib/resolvers/count.js:40:33\r\n  - connectionResolver.js:147 _callee$\r\n    [npm_ram_disk]/[graphql-compose-connection]/lib/connectionResolver.js:147:34\r\n  - runtime.js:62 tryCatch\r\n    [npm_ram_disk]/[regenerator-runtime]/runtime.js:62:40\r\n  - runtime.js:296 Generator.invoke [as _invoke]\r\n    [npm_ram_disk]/[regenerator-runtime]/runtime.js:296:22\r\n  - runtime.js:114 Generator.prototype.(anonymous function) [as next]\r\n    [npm_ram_disk]/[regenerator-runtime]/runtime.js:114:21\r\n  - asyncToGenerator.js:17 step\r\n    [npm_ram_disk]/[babel-runtime]/helpers/asyncToGenerator.js:17:30\r\n  - asyncToGenerator.js:35\r\n    [npm_ram_disk]/[babel-runtime]/helpers/asyncToGenerator.js:35:14\r\n  - Promise\r\n  - _export.js:35 F\r\n    [npm_ram_disk]/[core-js]/library/modules/_export.js:35:28\r\n  - asyncToGenerator.js:14\r\n    [npm_ram_disk]/[babel-runtime]/helpers/asyncToGenerator.js:14:12\r\n  - connectionResolver.js:275 resolve\r\n    [npm_ram_disk]/[graphql-compose-connection]/lib/connectionResolver.js:275:21\r\n  - resolver.js:523\r\n    [npm_ram_disk]/[graphql-compose]/lib/resolver.js:523:18\r\n  - resolver.js:523\r\n    [npm_ram_disk]/[graphql-compose]/lib/resolver.js:523:18\r\n  - resolver.js:523\r\n    [npm_ram_disk]/[graphql-compose]/lib/resolver.js:523:18\r\n  - jobTC.js:554 rp\r\n    /Volumes/npm_ram_disk/build/development/webpack:/src/schema/job/jobTC.js:554:1\r\n  - resolver.js:354\r\n    [npm_ram_disk]/[graphql-compose]/lib/resolver.js:354:18\r\n  - resolver.js:341 resolve\r\n    [npm_ram_disk]/[graphql-compose]/lib/resolver.js:341:29\r\n  - Array.reduce\r\n  - Array.reduce\r\n  - index.js:164\r\n    [npm_ram_disk]/[express-graphql]/dist/index.js:164:37\r\n  - next_tick.js:228 process._tickDomainCallback\r\n    internal/process/next_tick.js:228:7\r\n</details>\r\n\r\n\r\n### As a workaround what you can suggest me?\r\nHow to remove some keys from creteria? Is there public mongoose api for this:\r\n```diff\r\nconst userQuery = User.where({ status: 'approved' });\r\nconst someFilter = { status: { $ne: 'delayed' } };\r\n\r\nObject.keys(someFilter).forEach(key => {\r\n-   delete userQuery._criteria[key];\r\n+   some proper way to remove existed condition, for avoiding incorrect merge behavior\r\n});\r\n \r\nconst data = await userQuery.where(someFilter).exec();\r\n```"}}
{"actor":{"display_login":"nodkz"}}