iot-dc3.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright 2016-present Pnoker All Rights Reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. * https://www.apache.org/licenses/LICENSE-2.0
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. */
  14. db = db.getSiblingDB("admin");
  15. db = db.getSiblingDB("authorization");
  16. if (!db.getUser("admin")) {
  17. db.createUser({
  18. user: "admin",
  19. pwd: "dc3",
  20. roles: [
  21. {
  22. role: "readWrite",
  23. db: "authorization",
  24. },
  25. ],
  26. });
  27. }
  28. db = db.getSiblingDB("admin");
  29. if (!db.getUser("admin")) {
  30. db.createUser({
  31. user: "admin",
  32. pwd: "dc3",
  33. roles: [
  34. {
  35. role: "readWrite",
  36. db: "admin",
  37. },
  38. ],
  39. });
  40. }
  41. db = db.getSiblingDB("dc3");
  42. if (!db.getUser("dc3")) {
  43. db.createUser({
  44. user: "dc3",
  45. pwd: "dc3",
  46. roles: [
  47. {
  48. role: "readWrite",
  49. db: "dc3",
  50. },
  51. ],
  52. });
  53. }
  54. if (db.createCollection("point_value")) {
  55. db.pointValue.createIndex(
  56. {
  57. deviceId: 1,
  58. pointId: 1,
  59. },
  60. {
  61. name: "IX_device_point_id",
  62. unique: false,
  63. background: true,
  64. }
  65. );
  66. db.pointValue.createIndex(
  67. {
  68. createTime: 1,
  69. },
  70. {
  71. name: "IX_create_time",
  72. unique: false,
  73. background: true,
  74. }
  75. );
  76. }
  77. if (db.createCollection("driver_event")) {
  78. db.driverEvent.createIndex(
  79. {
  80. driverId: 1,
  81. },
  82. {
  83. name: "IX_driver_id",
  84. unique: false,
  85. background: true,
  86. }
  87. );
  88. db.driverEvent.createIndex(
  89. {
  90. createTime: 1,
  91. },
  92. {
  93. name: "IX_create_time",
  94. unique: false,
  95. background: true,
  96. }
  97. );
  98. }
  99. if (db.createCollection("device_event")) {
  100. db.deviceEvent.createIndex(
  101. {
  102. deviceId: 1,
  103. pointId: 1,
  104. },
  105. {
  106. name: "IX_device_point_id",
  107. unique: false,
  108. background: true,
  109. }
  110. );
  111. db.deviceEvent.createIndex(
  112. {
  113. createTime: 1,
  114. },
  115. {
  116. name: "IX_create_time",
  117. unique: false,
  118. background: true,
  119. }
  120. );
  121. }