These are chat archives for Automattic/mongoose

10th
Jul 2018
himStone
@himStone
Jul 10 2018 04:13
hello, I'm new to mongoose. Does anyone know mongoose support GridFS ?
Kev
@lineus
Jul 10 2018 10:57
@himStone only in the sense that you have access to the underlying native driver which makes it pretty easy.
Ian Paschal
@ianpaschal
Jul 10 2018 11:11
another question: how can I get my mongoose schema into the front end to generate a form for it? every attempt of mine has failed because of mongoose dependencies (not within schema, as far as i can tell)
only solution i can imagine right now is actually to define all my schemas separately as vanilla JS objects in their own files and then import each of htose objects into a a file each makes a mongoose Schema and Model instance for each
feels stupid and messy though and makes 2x as many files
panigrah
@panigrah
Jul 10 2018 11:20
@ianpaschal store all the schemes in a database as JSON strings. Use them in the backend and front end.
Ian Paschal
@ianpaschal
Jul 10 2018 11:25
hmm can better use JS objects i think
doesn’t make sense to have to modify a db record to change your schemas
Kev
@lineus
Jul 10 2018 11:27
@ianpaschal there's also a browser.js file at the top level of the mongoose package you can use to require or import mongoose into your frontend code. docs here
Ian Paschal
@ianpaschal
Jul 10 2018 11:27
i think thats what i was looking for. i need to go post this in all those stack overflow threads of people asking about this with no good answer. reap that sweet sweet karma
hmm yes looks perfect. also strange that it didn’t come up in any google searches and isn’t in the docs sidebar 🤔
well hidden
Kev
@lineus
Jul 10 2018 11:31
yeah I just made a note to file a PR with an addition to the sidebar :) I only knew about it because I saw it come up in an issue a while back.
Ian Paschal
@ianpaschal
Jul 10 2018 11:31
thanks again @lineus
actually i think this is the 3rd time you answered my questions and 2nd time a case of “what, how can this not be a thing in mongoose” turned out “actually it is a thing"
Kev
@lineus
Jul 10 2018 11:33
glad to help @ianpaschal
I'll see if I can put together a PR to make GridFSBucket easier with mongoose, it would be cool not to have to drop down into the native driver to get it done.
Ian Paschal
@ianpaschal
Jul 10 2018 14:46
@lineus I'm not able to get the browser thing to work. using import mongoose from 'mongoose/browser'; still causes the following errors in webpack:
WARNING in ./node_modules/mongoose/lib/drivers/index.js
10:13-49 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/mongoose/lib/drivers/index.js
 @ ./node_modules/mongoose/lib/schema.js
 @ ./node_modules/mongoose/lib/browser.js
 @ ./node_modules/mongoose/browser.js
 @ ./src/store/index.js
 @ ./src/client.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/client.js

WARNING in ./node_modules/require_optional/index.js
82:18-42 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/require_optional/index.js
 @ ./node_modules/mongoose/node_modules/mongodb-core/index.js
 @ ./node_modules/mongoose/node_modules/mongodb/index.js
 @ ./node_modules/mongoose/lib/drivers/node-mongodb-native/binary.js
 @ ./node_modules/mongoose/lib/drivers/node-mongodb-native/index.js
 @ ./node_modules/mongoose/lib/drivers/index.js
 @ ./node_modules/mongoose/lib/schema.js
 @ ./node_modules/mongoose/lib/browser.js
 @ ./node_modules/mongoose/browser.js
 @ ./src/store/index.js
 @ ./src/client.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/client.js

WARNING in ./node_modules/require_optional/index.js
90:20-44 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/require_optional/index.js
 @ ./node_modules/mongoose/node_modules/mongodb-core/index.js
 @ ./node_modules/mongoose/node_modules/mongodb/index.js
 @ ./node_modules/mongoose/lib/drivers/node-mongodb-native/binary.js
 @ ./node_modules/mongoose/lib/drivers/node-mongodb-native/index.js
 @ ./node_modules/mongoose/lib/drivers/index.js
 @ ./node_modules/mongoose/lib/schema.js
 @ ./node_modules/mongoose/lib/browser.js
 @ ./node_modules/mongoose/browser.js
 @ ./src/store/index.js
 @ ./src/client.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/client.js

WARNING in ./node_modules/require_optional/index.js
97:35-67 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/require_optional/index.js
 @ ./node_modules/mongoose/node_modules/mongodb-core/index.js
 @ ./node_modules/mongoose/node_modules/mongodb/index.js
 @ ./node_modules/mongoose/lib/drivers/node-mongodb-native/binary.js
 @ ./node_modules/mongoose/lib/drivers/node-mongodb-native/index.js
 @ ./node_modules/mongoose/lib/drivers/index.js
 @ ./node_modules/mongoose/lib/schema.js
 @ ./node_modules/mongoose/lib/browser.js
 @ ./node_modules/mongoose/browser.js
 @ ./src/store/index.js
 @ ./src/client.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/client.js

ERROR in ./node_modules/mongoose/node_modules/mongodb-core/lib/uri_parser.js
Module not found: Error: Can't resolve 'dns' in '/Users/Ian/Code/ianpaschal/chainline.io/node_modules/mongoose/node_modules/mongodb-core/lib'
 @ ./node_modules/mongoose/node_modules/mongodb-core/lib/uri_parser.js 4:12-26
 @ ./node_modules/mongoose/node_modules/mongodb-core/index.js
 @ ./node_modules/mongoose/node_modules/mongodb/index.js
 @ ./node_modules/mongoose/lib/drivers/node-mongodb-native/binary.js
 @ ./node_modules/mongoose/lib/drivers/node-mongodb-native/index.js
 @ ./node_modules/mongoose/lib/drivers/index.js
 @ ./node_modules/mongoose/lib/schema.js
 @ ./node_modules/mongoose/lib/browser.js
 @ ./node_modules/mongoose/browser.js
 @ ./src/store/index.js
 @ ./src/client.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/client.js

ERROR in ./node_modules/mongoose/node_modules/mongodb/lib/url_parser.js
Module not found: Error: Can't resolve 'dns' in '/Users/Ian/Code/ianpaschal/chainline.io/node_modules/mongoose/node_modules/mongodb/lib'
 @ ./node_modules/mongoose/node_modules/mongodb/lib/url_parser.js 7:8-22
 @ ./node_modules/mongoose/node_modules/mongodb/lib/mongo_client.js
 @ ./node_modules/mongoose/node_modules/mongodb/index.js
 @ ./
Kev
@lineus
Jul 10 2018 14:48
@ianpaschal did you add the node option to the config from the browser docs?
Ian Paschal
@ianpaschal
Jul 10 2018 14:54
ah no i didn't get past step 1 at the top of the page haha
got rid of the errors, still have all the warnings
Kev
@lineus
Jul 10 2018 14:58
If the exclude rule for /node_modules/i doesn't catch those it might be a bug worth reporting
Ian Paschal
@ianpaschal
Jul 10 2018 14:59
nop, doesn't fix it. will file report when i'm home
Kev
@lineus
Jul 10 2018 15:01
cool, thanks :+1:
Ian Paschal
@ianpaschal
Jul 10 2018 15:01
what is the meaning of the i?
Kev
@lineus
Jul 10 2018 15:02
just a guess, but it probably makes the match case-insensitive
Ian Paschal
@ianpaschal
Jul 10 2018 15:02

i already had

{
    test: /\.js$/,
    loader: "babel-loader",
    exclude: /node_modules/
},

in my webpack config but tried it both ways

makes sense i guess
Kev
@lineus
Jul 10 2018 15:02
i have pretty much 0 experience with webpack though