I'm trying to create a schema in MongoDB using deno_mongo for deno and MongoDB rust dive for rust but I cannot figure out if it is possible.
I want to execute something similar to this in Mongo CLI
db.createCollection('test',{
validator: {
$jsonSchema: {
bsonType: 'object',
required:['field1', 'field2'],
properties:{
field1: {
bsonType:'string',
description:'enter field1'
},
field2: {
bsonType:'string',
description:'enter field2'
}
}
);
deno_mongo does not support createCollection yet (28 September 2020). As Deno evolves there is most certainly going to be options for this but at not yet at the moment.
I tried to find a way to get the name of the database in use, but actually you can not even do that. With javascript you can only get the db["name"] property but that does not confirm the name from MongoDB. It is the same with createCollection.
There is not a createCollection command but there is db.runCommand() create which is not supported yet.
Also there is a way to run scripts in MongoDB shell which then manipulates your database as you wish.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With