These are chat archives for Automattic/mongoose

12th
Dec 2017
Paul "Joey" Clark
@joeytwiddle
Dec 12 2017 03:04
@fnoori You can get the underlying driver from mongoose, and do whatever you like with that.
mongooseConnection.db.createUser(…)
Caleb B
@zikeji
Dec 12 2017 05:58
Hey, I recently began running into this issue for no apparent reason. I've stepped through code and debugged as much as possible but I can't get a thumb on it. No changes were made, but I've still tried alot.
{
  "undefined": {
    "message": "Object prototype may only be an Object or null: undefined",
    "name": "ValidatorError",
    "properties": {
      "message": "Object prototype may only be an Object or null: undefined",
      "type": "cast"
    },
    "kind": "cast"
  }
}
Object prototype may only be an Object or null: undefined
    at new ValidatorError (C:\projects\indev\node_modules\mongoose\lib\error\validator.js:25:11)
    at _init (C:\projects\indev\node_modules\mongoose\lib\document.js:414:37)
    at init (C:\projects\indev\node_modules\mongoose\lib\document.js:381:7)
    at model.Document.init (C:\projects\indev\node_modules\mongoose\lib\document.js:343:3)
    at model._done (C:\projects\indev\node_modules\hooks-fixed\hooks.js:105:24)
    at _next (C:\projects\indev\node_modules\hooks-fixed\hooks.js:68:28)
    at fnWrapper (C:\projects\indev\node_modules\hooks-fixed\hooks.js:190:8)
    at model.<anonymous> (C:\projects\indev\node_modules\mongoose\lib\schema.js:1560:9)
    at model._next (C:\projects\indev\node_modules\hooks-fixed\hooks.js:63:32)
    at model.proto.(anonymous function) [as $__original_init] (C:\projects\indev\node_modules\hooks-fixed\hooks.js:112:20)
    at C:\projects\indev\node_modules\mongoose\lib\services\model\applyHooks.js:161:27
    at new Promise (<anonymous>)
    at model.wrappedPointCut [as init] (C:\projects\indev\node_modules\mongoose\lib\services\model\applyHooks.js:139:23)
    at completeOne (C:\projects\indev\node_modules\mongoose\lib\query.js:1952:10)
    at C:\projects\indev\node_modules\mongoose\lib\query.js:1492:13
    at C:\projects\indev\node_modules\mongoose\lib\model.js:4032:16
Caleb B
@zikeji
Dec 12 2017 06:04
I'm on Windows x64 w/ Node v8.9.1 (NPM 5.5.1/Yarn 1.3.2)
The weird thing about the issue is it comes up, I reinstall modules - sometimes it works, sometimes it doesn't. Cloning the repo makes it work for a short while as well. I've used different folders. Project runs completely fine on a different box. I'm at a loss
I've searched most resources available for a solution to no avail. There was no code changes or changes to my environment (that I'm aware of) when the problem began.
I though it was my transpiler (Babel) but I no longer think so after some messing around with that.
आदित्य शर्मा
@aadii104
Dec 12 2017 10:40
Guys I want to make a repository access level like github .
Please guide me how does schema look likes....
Caleb B
@zikeji
Dec 12 2017 16:42
This is rage inducing. Spend 3 hours troubleshooting, randomly starts working for no apparent reason. Go and get a coffee? Come back and it's no longer working.
Paul "Joey" Clark
@joeytwiddle
Dec 12 2017 17:18
@zikeji It's difficult to help you without seeing your code.
Perhaps you don't know which part of your code is triggering this?
If that is the case, I recommend installing and loading the longjohn package. It may be able to show you a more detailed stacktrace.
You could also try different versions of mongoose, Node, or a different OS in a virtual machine, to try to isolate the cause.
Caleb B
@zikeji
Dec 12 2017 17:55
Tried everything in your last statement. I'll give longjohn a try.
If longjohn doesn't help I'll get a repro repo up and going
Caleb B
@zikeji
Dec 12 2017 19:05
Only getting this out of longjohn
Object prototype may only be an Object or null: undefined
    at new ValidatorError (C:\projects\indev\node_modules\mongoose\lib\error\validator.js:25:11)
    at _init (C:\projects\indev\node_modules\mongoose\lib\document.js:417:37)
    at init (C:\projects\indev\node_modules\mongoose\lib\document.js:384:7)
    at EmbeddedDocument.Document.init (C:\projects\indev\node_modules\mongoose\lib\document.js:346:3)
    at DocumentArray.cast (C:\projects\indev\node_modules\mongoose\lib\schema\documentarray.js:310:27)
    at _init (C:\projects\indev\node_modules\mongoose\lib\document.js:415:29)
    at init (C:\projects\indev\node_modules\mongoose\lib\document.js:384:7)
    at model.Document.init (C:\projects\indev\node_modules\mongoose\lib\document.js:346:3)
    at model._done (C:\projects\indev\node_modules\hooks-fixed\hooks.js:105:24)
    at _next (C:\projects\indev\node_modules\hooks-fixed\hooks.js:68:28)
    at fnWrapper (C:\projects\indev\node_modules\hooks-fixed\hooks.js:190:8)
    at model.<anonymous> (C:\projects\indev\node_modules\mongoose\lib\schema.js:1560:9)
    at model._next (C:\projects\indev\node_modules\hooks-fixed\hooks.js:63:32)
    at model.proto.(anonymous function) [as $__original_init] (C:\projects\indev\node_modules\hooks-fixed\hooks.js:112:20)
    at C:\projects\indev\node_modules\mongoose\lib\services\model\applyHooks.js:161:27
    at new Promise (<anonymous>)
    at model.wrappedPointCut [as init] (C:\projects\indev\node_modules\mongoose\lib\services\model\applyHooks.js:139:23)
    at completeOne (C:\projects\indev\node_modules\mongoose\lib\query.js:2001:10)
    at C:\projects\indev\node_modules\mongoose\lib\query.js:1541:13
    at C:\projects\indev\node_modules\mongoose\lib\model.js:4054:16
    at next (C:\projects\indev\node_modules\mongoose\lib\model.js:3180:5)
    at next (C:\projects\indev\node_modules\mongoose\lib\model.js:3297:7)
Caleb B
@zikeji
Dec 12 2017 23:51
This makes no sense. I add a console.log after this.findById in a schema static, reload the dev server, it's working happy and dandy again. I restart the dev server just to see, still working. I remove the console.log? Now I get the same error again. Okay.. Weird, I put it back. Still getting the same error.