mongoose icon indicating copy to clipboard operation
mongoose copied to clipboard

bugs during update from 4.7.2 to 4.7.3

Open worotyns opened this issue 9 years ago • 22 comments

Hello,

Yesterday after update the mongoose to 4.7.3 i hava some trouble with "all" tests in my application All tests returns me: Validation Errors, and Cast errors, TypeError: Cannot read property 'remove' of undefined;

Sample error:

 CastError: Cast to ObjectId failed for value "586b672be11a4670c4eb3f66" at path "_id" for model "User"
      at MongooseError.CastError (/common/node_modules/mongoose/lib/error/cast.js:26:11)
      at ObjectId.cast (/common/node_modules/mongoose/lib/schema/objectid.js:147:13)
      at ObjectId.castForQuery (/common/node_modules/mongoose/lib/schema/objectid.js:187:15)
      at cast (/common/node_modules/mongoose/lib/cast.js:229:32)
      at Query.cast (/common/node_modules/mongoose/lib/query.js:2752:12)
      at Query.findOne (/common/node_modules/mongoose/lib/query.js:1353:10)
      at /common/node_modules/mongoose/lib/query.js:2310:21
      at Query.exec (/common/node_modules/mongoose/lib/query.js:2304:17)
      at Query.then (/common/node_modules/mongoose/lib/query.js:2351:15)
      at next (/common/node_modules/co/index.js:100:51)
      at onFulfilled (/common/node_modules/co/index.js:69:7)
      at /common/node_modules/co/index.js:54:5
      at co (/common/node_modules/co/index.js:50:10)
      at Test.<anonymous> (src/routes/me.spec.js:169:11)
      at Test.assert (/common/node_modules/supertest/lib/test.js:156:6)
      at Server.assert (/common/node_modules/supertest/lib/test.js:127:12)
      at emitCloseNT (net.js:1537:8)

Let me know what more informations you know.

worotyns avatar Jan 03 '17 09:01 worotyns

We are having the same problem.

Our version is: mongoose 4.7.4

could it be related with the leap second?

karliky avatar Jan 03 '17 09:01 karliky

We are having the same problem.

stackcats avatar Jan 03 '17 09:01 stackcats

We are having the same problem.

wh-gd avatar Jan 03 '17 09:01 wh-gd

We are having the same problem.

chinaguo avatar Jan 03 '17 09:01 chinaguo

We are having the same problem.

wangpeiyong avatar Jan 03 '17 10:01 wangpeiyong

We also have this problem:

"TypeError: Unknown encoding: 2",
        " at Buffer.slowToString (buffer.js:363:17)",
        " at Buffer.toString (buffer.js:376:27)",
        " at ObjectID.toString (/data/home/project/node_modules/mongodb-core/node_modules/bson/lib/bson/objectid.js:174:20)",

which is similar to this one https://travis-ci.org/Automattic/mongoose/jobs/188445650 :

  1) document bug fixes toObject() with buffer and minimize (gh-4800):
     TypeError: Unknown encoding: 1
      at Buffer.slowToString (buffer.js:487:17)
      at Buffer.toString (buffer.js:500:27)
      at ObjectID.toString (node_modules/bson/lib/bson/objectid.js:174:20)

karliky avatar Jan 03 '17 10:01 karliky

We think that this issue is related with this commit https://github.com/mongodb/js-bson/commit/e136ac084a8a3db135a9e36efa157f517b5336e4 or at least with that package

karliky avatar Jan 03 '17 10:01 karliky

Hi @vkarpov15 We have performed some tests locally and have seen that in this line https://github.com/Automattic/mongoose/blob/master/lib/schema/objectid.js#L147 ...the error that is being catched and transformed into a CastError is this:

[TypeError: hex is not a function]

We have tried tracking this through the dependencies, and if we got this right, this goes all the way down to the bson package which happens to have been updated 19h ago (https://www.npmjs.com/package/bson) and seems to involve some validation changes in the ObjectId type (https://github.com/mongodb/js-bson/commit/e136ac084a8a3db135a9e36efa157f517b5336e4)

... bson is listed in mongoose's package.json with ~1.0.1 and the latest version is 1.0.2.

In my local environment, where I can reproduce this, bson has been updated to the 1.0.2 as a dependency of mongodb-core.

├─┬ [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ └─┬ [email protected]
│ │ │   └── [email protected]
│ │ └─┬ [email protected]
│ │   └── [email protected]

JvrBaena avatar Jan 03 '17 10:01 JvrBaena

same here its :(

msxenon avatar Jan 03 '17 10:01 msxenon

bson problem was fixed with v1.0.3

https://github.com/Automattic/mongoose/issues/4864 https://github.com/mongodb/js-bson/commit/35f5264446fb74e475ecf25f94ce7b177b5b35fd

Re-intstall all deps, verify that bson is v1.0.3 and see if it works now.

skcc75 avatar Jan 03 '17 17:01 skcc75

~~Reinstalling deps fixes this at least in my local env~~. Still ... don't know if the dependency for bson should be fixed in the package.json to avoid this unexpected behaviours suddenly breaking stuff everywhere. There's already a PR for that: https://github.com/Automattic/mongoose/issues/4862

In any case thanks for the heads up @kyrylkov :)

EDIT: ...maybe I talked too fast. Still seeing this behaviour after correctly reinstalling dependencies and getting bson 1.0.3 😭 😭

JvrBaena avatar Jan 03 '17 17:01 JvrBaena

Looks like there's already a PR in the bson module that fixes the root of this problem https://github.com/mongodb/js-bson/issues/204

JvrBaena avatar Jan 04 '17 09:01 JvrBaena

We are having the same problem.

aboutvale avatar Jan 04 '17 10:01 aboutvale

We are having the same problem.

Our version is: 4.7.6

var mongoose = require('mongoose');
var id = mongoose.Types.ObjectId('4edd40c86762e0fb12000003');  // err!
console.log(typeof id); 
TypeError: hex is not a function

ifyour avatar Jan 04 '17 10:01 ifyour

Found a temporary solution:

npm install [email protected]

ifyour avatar Jan 04 '17 11:01 ifyour

same here. different problems, mostly combined with _id's

pszabo1 avatar Jan 04 '17 15:01 pszabo1

#same issue doesn't recognize valid _id's

@ifyour temporary version drop to mongoose 4.7.2, fixes the issue

jrfoxw avatar Jan 05 '17 23:01 jrfoxw

Closing this as it's a duplicate of https://github.com/Automattic/mongoose/issues/4867

sobafuchs avatar Jan 06 '17 04:01 sobafuchs

I am having the same issue and switching to [email protected] is not working.

I have posted this issue here. I am badly stuck.

I upgraded my node version to v9.6.1 and downgraded mongoose to 4.7.2. It's been more than 24 hours!

What is the solution?

aimenbatool avatar Aug 20 '18 16:08 aimenbatool

@aimenbatool upgrade to >= 4.7.7. If you still have problems, open up a new issue with detailed code samples.

vkarpov15 avatar Aug 23 '18 20:08 vkarpov15