Advertisement
Guest User

Untitled

a guest
Oct 24th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. db.createCollection( "vehicles" , {
  2. validator: { $jsonSchema: {
  3. bsonType: "object",
  4. required: [ "storage_number", "identificator"],
  5. properties: {
  6. storage_number: {
  7. bsonType: "string",
  8. description: "required and must be a valid string (3 Letters A to Z)" },
  9. identificator: {
  10. bsonType: "string",
  11. description: "required and must be a vlid string (5 numbers from 0 to 9)" }
  12. }
  13. }
  14. }})
  15.  
  16. db.vehicles.insert({
  17. storage_number: 'BMV',
  18. identificator: '5464564'
  19. })
  20.  
  21. db.createCollection( "vehicles" , {
  22. validator: { $jsonSchema: {
  23. bsonType: "object",
  24. required: [ "minimumPeople"],
  25. properties: {
  26. minimumPeople: {
  27. bsonType: "int",
  28. minimum: 2,
  29. description: "there must be minimum of 2 people" }
  30. }
  31. }
  32. }})
  33.  
  34.  
  35. db.runCommand( {
  36. collMod: "vehicles",
  37. validator: { $jsonSchema: {
  38. bsonType: "object",
  39. required: ["minimumPeople"],
  40. properties: {
  41. minimumPeople: {
  42. bsonType: "int",
  43. minimum: 2,
  44. description: "there must be minimum of 2 people" }
  45. }
  46. } }
  47. })
  48.  
  49.  
  50. db.vehicles.update(
  51. {},
  52. { $set: {"new_field": null} },
  53. false,
  54. true
  55. )
  56.  
  57.  
  58. var generateCargoName = function () {
  59. var cargoName = [ 'Krastavici',
  60. 'Domati',
  61. 'Morkovi',
  62. 'Zele',
  63. 'Banani',
  64. 'Qbylki'
  65. ];
  66. return cargoName[Math.floor(Math.random() * 6)];
  67. }
  68.  
  69. var generateCategory = function () {
  70. var categories = [ 'Zelenchuci',
  71. 'Plodove'
  72. ];
  73. return categories[Math.floor(Math.random() * 2)];
  74. }
  75.  
  76. var fillCargo = function(){
  77. var vehicles = db.vehicles.find().toArray();
  78. var cargo = {}
  79.  
  80. for(i = 0; i < vehicles.length; i++){
  81. cargo.name = generateCargoName();
  82. cargo.category = generateCategory();
  83. cargo.quantity = Math.floor(Math.random + 200) + 1;
  84. cargo.vehicle_Id = vehicles[i]._id;
  85.  
  86. db.cargo.insert(cargo);
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement