0

I know the benefits of an object database is that the data can be loaded and saved in the format you will probably be using it in. But if i'm loading an object from a database, manipulating it on the client, and sending it back, how do I ensure new data doesn't maliciously get in?

[GET] => /users/1

{
  "name": "john doe"
}

[PUT] => /users/1

{
  "name": "john doe",
  "extra properties": "just cluttering your db"
}

That also brings up the question as to how you prevent a number getting set as an int? Is there a schema you can attach to a database? Do you need to use a mapper?

micah
  • 7,596
  • 10
  • 49
  • 90

1 Answers1

0

Don't know exactly If there is a standard schema but one thing You can do that answer your questions is use the mongoDB document validator. It was introduced in version 3.2 and allow you to validate documents during updates and insertions. It need to be defined when the collection is being created.

The int case It'd be:

db.createCollection( "users",
   { validator: {
       number: { $type: "int" }
   }
} )

Document validator support types:

https://docs.mongodb.com/manual/reference/operator/query/type/

Official info about document validator:

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