Advertisement
ronikuchan

Sintaks MongoDB

Oct 6th, 2019
598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.09 KB | None | 0 0
  1. Sintaks MongoDB
  2. ambil wilayah kota
  3. db.wilayah.find({kode: {$regex: /^\d{2}\.\d{2}$/}}) -> 90.12
  4.  
  5.  
  6. penggunaan and
  7.  
  8. contoh 1
  9. db.wilayah.find(
  10. {
  11. $and:
  12. [
  13. {
  14. kode:
  15. {
  16. $regex: /^32.01/
  17. }
  18. },
  19. {
  20. kode:
  21. {
  22. $regex:/^\d{2}\.\d{2}\.\d{2}\.\d{4}$/
  23. }
  24. }
  25. ]
  26. }
  27. ).limit(2000)
  28.  
  29.  
  30. contoh 2
  31. db.detail_produk_mitra.find(
  32. {
  33. $and:
  34. [
  35. { distribusi_id: "5e2a6d8b48af850035664652"},
  36. { produk_mitra_id: "5e2a722348af8500390ffcb5"}
  37. ]
  38.  
  39. })
  40. .projection({})
  41. .sort({_id:-1})
  42. .limit(100)
  43.  
  44. db.produk_mitra.find(
  45. {
  46. // produk_id: "5e04376b5f6d823f635c2822",
  47. // mitra_id: "5df0d671d0f4eb17823fb352"
  48. $and:
  49. [
  50. { produk_id: "5e04376b5f6d823f635c2822"},
  51. { mitra_id: "5e182f2ca24c7837187a4678"}
  52. ]
  53.  
  54. })
  55. .projection({})
  56. .sort({_id:-1})
  57. .limit(100)
  58.  
  59. # Users Address
  60. db.users_address.find(
  61. {
  62. user_id: "5ea424254c1e381d62441fde"
  63. // $and:
  64. // [
  65. // { kota: "36.71"},
  66. // { kecamatan: "36.71.04"},
  67. // { kelurahan: "36.71.04.1003"}
  68. // ]
  69.  
  70. })
  71. .projection({})
  72. .sort({_id:-1})
  73. .limit(100)
  74.  
  75. db.transaksi.find(
  76. {
  77. $and:
  78. [
  79. { mitra_id: "5e67666e42494e392720b6d4"},
  80. { mitra_id: {$type: "string"}}
  81. ]
  82.  
  83. })
  84. .projection({})
  85. .sort({_id:-1})
  86. .limit(100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement