You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
and return the serialized version of the schema found in the collection. Should thinly wrap .find() with all its parameters, like query, skip, limit, etc
Hi @Mogztter I don't think we need a mongo shell plugin for this library anymore now that the new mongo shell (mongosh) can import npm modules natively. I just tested the following to confirm:
Install this module into your local working directory with npm install mongodb-schema
Open the (new) mongo shell with mongosh
Require the module with schema = require('mongodb-schema')
The integration could probably be improved. I wasn't able to pass in the cursor of a find() directly into the function, instead you'll have to convert it to an array first.
But I hope this will get you going in the mean time.
I'm unsure about your comment regarding PyMongo. This is a Javascript library and you won't be able to use it directly from Python though.
One small thing to note: mongosh has an experimental feature called snippets, for even more seamlessly integrating external packages into mongosh: https://github.com/mongodb-labs/mongosh-snippets
My understanding was that the MongoDB engine was able to execute JavaScript code (using eval). So I was expecting something like:
That’s true, but db.eval() runs code on the server, where require() is not a thing (because it’s a Node.js/mongosh-specific concept) and mongodb-schema is almost surely not installed to begin with.
One small thing to note: mongosh has an experimental feature called snippets, for even more seamlessly integrating external packages into mongosh: mongodb-labs/mongosh-snippets
So snippet install installs the module client side, right?
That’s true, but db.eval() runs code on the server, where require() is not a thing (because it’s a Node.js/mongosh-specific concept) and mongodb-schema is almost surely not installed to begin with.
Yes but let's say we provide mongodb-schema as a single file (for instance using https://github.com/vercel/ncc), then it would technically be possible to use mongodb-schema with db.eval()?
Out of curiosity, is there a better way than db.eval()? It seems that this (quite useful) function is deprecated:
So snippet install installs the module client side, right?
Yes, exactly 👍
Yes but let's say we provide mongodb-schema as a single file (for instance using https://github.com/vercel/ncc), then it would technically be possible to use mongodb-schema with db.eval()?
Sure – I don’t think ncc is what you want, but bundlers in general could probably give you this functionality.
Out of curiosity, is there a better way than db.eval()? It seems that this (quite useful) function is deprecated:
I’m not sure, but generally, most server-side JS execution is at least discouraged. Maybe ask yourself, why do you need this to be server-side and not client-side?
Activity
imlucas commentedon Jun 26, 2015
Made https://jira.mongodb.org/browse/INT-317 to track background work to make this happen
ggrossetie commentedon Sep 7, 2021
@imlucas it seems that the issue no longer exists in JIRA:
@rueckstiess is there any news regarding this issue? I would be interested in using this library with PyMongo and MongoDB 5. Thanks!
rueckstiess commentedon Sep 8, 2021
Hi @Mogztter I don't think we need a mongo shell plugin for this library anymore now that the new mongo shell (mongosh) can import npm modules natively. I just tested the following to confirm:
npm install mongodb-schema
mongosh
schema = require('mongodb-schema')
The integration could probably be improved. I wasn't able to pass in the cursor of a find() directly into the function, instead you'll have to convert it to an array first.
But I hope this will get you going in the mean time.
I'm unsure about your comment regarding PyMongo. This is a Javascript library and you won't be able to use it directly from Python though.
ggrossetie commentedon Sep 8, 2021
Oh, that's nice!
My understanding was that the MongoDB engine was able to execute JavaScript code (using
eval
). So I was expecting something like:Similar to https://github.com/variety/variety#an-easy-example
addaleax commentedon Sep 8, 2021
Oh hi! I didn’t know that this existed.
One small thing to note: mongosh has an experimental feature called snippets, for even more seamlessly integrating external packages into mongosh: https://github.com/mongodb-labs/mongosh-snippets
You can run
snippet install analyze-schema
and then callschema()
on collections and cursors: https://github.com/mongodb-labs/mongosh-snippets/tree/main/snippets/analyze-schemaThat’s true, but
db.eval()
runs code on the server, whererequire()
is not a thing (because it’s a Node.js/mongosh-specific concept) andmongodb-schema
is almost surely not installed to begin with.ggrossetie commentedon Sep 8, 2021
👍🏻
Neat, I will give it a try.
So
snippet install
installs the module client side, right?Yes but let's say we provide
mongodb-schema
as a single file (for instance using https://github.com/vercel/ncc), then it would technically be possible to usemongodb-schema
withdb.eval()
?Out of curiosity, is there a better way than
db.eval()
? It seems that this (quite useful) function is deprecated:Thanks!
addaleax commentedon Sep 8, 2021
Yes, exactly 👍
Sure – I don’t think ncc is what you want, but bundlers in general could probably give you this functionality.
I’m not sure, but generally, most server-side JS execution is at least discouraged. Maybe ask yourself, why do you need this to be server-side and not client-side?
ggrossetie commentedon Sep 10, 2021
I see, thanks for your reply 🤗