1

I would like to use the MongoDB native schema functionality in a Node application using the MongoDB NodeJS driver.

I do not want to use Mongoose for this. Mongoose has it's own implementation of Schemas, but has different issues which makes me want to use MongoDB directly.

So far, I have only been able to find how to create a in (official) documentation using the MongoDB via the command line only. I cannot find or figure out how to do this from within a NodeJS app using the NodeJS MongoDB driver.

Also, I cannot find any documentation on how to alter the Schema if one has already been set on a collection.

Anybody know how to do this?

The official docs that I have seen about this topic can be found here:

https://docs.mongodb.com/manual/core/schema-validation/

closed as too broad by John Eisbrener, Vérace, Marco, dezso, kevinsky Apr 18 at 13:24

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Hi, welcome to dba.se. Is there any way you can update your question to include some more specifics, such as what you've already done, what you've tried, and what is giving you trouble? Right now, the question is a bit too broad and needs some revision so that people can better help you (as well as anyone else that stumbles across this question in the future who has the same problem). – John Eisbrener Apr 16 at 14:43
  • @mani, I do appreciate your attempt to point me in the right direction, but I am not trying to perform crud operations, but trying to set a $jsonSchema for a collection that already exists or to change the Schema after a while when the requirements change. I can only find how to create a collection that has a schema in the MongoDB Shell, not how to change it or add one if no schema has been set. And then also do all this from inside a NodeJS app: docs.mongodb.com/manual/core/schema-validation – Chris V Apr 16 at 18:12
  • If my understanding is correct, you are looking for Object Document Mapper. mongoose is a javascript framework which can help you with your requirement mongoosejs.com/docs/guide.html – Mani Apr 16 at 18:19
  • @mani. Indeed, Mongoose is able to work with Schemas, but has its own implementation. I would like to work directly with MongoDB for performance reasons and would like to have a more direct way to implement a GridFS solution for user data-storage. Last time I looked into this, Mongoose had issues with this. Hence I would like to find a solution without the use of Mongoose – Chris V Apr 16 at 19:41

Browse other questions tagged or ask your own question.