Advertisement
Guest User

Untitled

a guest
May 6th, 2015
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.95 KB | None | 0 0
  1. use khdb
  2. switched to db khdb
  3. > db.desserts.insert({name: "salad", price: 15.50})
  4. ^[[A^[[A^[[A^[[AWriteResult({ "nInserted" : 1 })
  5. > db.desserts.insert({name: "milkshake", price: 8.50, discount: 2})
  6. WriteResult({ "nInserted" : 1 })
  7. > db.desserts.insert({name: "cake", price: 6.50})
  8. WriteResult({ "nInserted" : 1 })
  9. > db.category.insert({name:"food"})
  10. WriteResult({ "nInserted" : 1 })
  11. > db.category.insert({name:"snack"})
  12. WriteResult({ "nInserted" : 1 })
  13. > db.category.insert({name:"sweet"})
  14. WriteResult({ "nInserted" : 1 })
  15. > db.category.insert({name:"fruit"})
  16. WriteResult({ "nInserted" : 1 })
  17. > db.products.insert({name:"bread", kcal: 70})
  18. WriteResult({ "nInserted" : 1 })
  19. > khdb.product.insert({name: "banana", price: 2.50})
  20. 2015-04-30T13:24:25.190+0200 E QUERY ReferenceError: khdb is not defined
  21. at (shell):1:1
  22. > db.products.insert({name:"crisps", kcal: 460})
  23. WriteResult({ "nInserted" : 1 })
  24. > db.products.insert({name:"chocolate", kcal: 511})
  25. WriteResult({ "nInserted" : 1 })
  26. > db.products.insert({name:"apple", kcal: 60})
  27. WriteResult({ "nInserted" : 1 })
  28. > db.desserts.update({$mul: {price: 0.95}})
  29. 2015-04-30T13:27:30.423+0200 E QUERY Error: need an object
  30. at Error (<anonymous>)
  31. at DBCollection._parseUpdate (src/mongo/shell/collection.js:400:21)
  32. at DBCollection.update (src/mongo/shell/collection.js:432:23)
  33. at (shell):1:13 at src/mongo/shell/collection.js:400
  34. > db.desserts.update({name: "salad"},{$mul: {price: 0.95}})
  35. WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
  36. > db.desserts.update({},{$mul: {price: 0.95}})
  37. WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
  38. > db.desserts.update({},{$mul: {price: 0.95}})
  39. WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
  40. > db.desserts.update({},{$mul: {price: 0.95}}, {multi:true})
  41. WriteResult({ "nMatched" : 3, "nUpserted" : 0, "nModified" : 3 })
  42. > db.desserts.update({category:"fruit"},{$mul: {kcal: 0.95}}, {multi:true})
  43. WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })
  44. > db.products.update({category:"fruit"},{$mul: {kcal: 0.95}}, {multi:true})
  45. WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })
  46. > db.products.update({name: "bread"}, {$set: {category: "food"}})
  47. WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
  48. > db.products.update({name: "apple"}, {$set: {category: "fruit"}})
  49. WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
  50. > db.products.update({name: "banana"}, {$set: {category: "fruit"}})
  51. WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })
  52. > db.products.update({name: "chocolate"}, {$set: {category: "sweet"}})
  53. WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
  54. > db.desserts.update({category:"fruit"},{$mul: {kcal: 0.95}}, {multi:true})
  55. WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })
  56. > db.products.update({name: "chocolate"}, {$set: {category: "sweet"}})
  57. WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })
  58. > db.products.update({category:"fruit"},{$mul: {kcal: 0.95}}, {multi:true})
  59. WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
  60. > db.products.insert({name:"banana", kcal: 130, category: "fruit"})
  61. WriteResult({ "nInserted" : 1 })
  62. > db.products.update({category:"fruit"},{$mul: {kcal: 1.1}}, {multi:true})
  63. WriteResult({ "nMatched" : 2, "nUpserted" : 0, "nModified" : 2 })
  64. > db.products.count()
  65. 5
  66. > db.desserts.count()
  67. 3
  68. > db.products.update({category:"fruit"},{$set: {eko: 2}}, {multi:true})
  69. WriteResult({ "nMatched" : 2, "nUpserted" : 0, "nModified" : 2 })
  70. > db.products.find({kcal:{$gte : 100}})
  71. { "_id" : ObjectId("554210f80cd6fe3ad7ecab72"), "name" : "crisps", "kcal" : 460 }
  72. { "_id" : ObjectId("5542110a0cd6fe3ad7ecab73"), "name" : "chocolate", "kcal" : 511, "category" : "sweet" }
  73. { "_id" : ObjectId("5542134e0cd6fe3ad7ecab75"), "name" : "banana", "kcal" : 143, "category" : "fruit", "eko" : 2 }
  74. > db.products.find({kcal:{$gte : 100, category: "fruit"}})
  75. Error: error: {
  76. "$err" : "Can't canonicalize query: BadValue unknown operator: category",
  77. "code" : 17287
  78. }
  79. > db.products.find({kcal:{$gte : 100}, category: "fruit"})
  80. { "_id" : ObjectId("5542134e0cd6fe3ad7ecab75"), "name" : "banana", "kcal" : 143, "category" : "fruit", "eko" : 2 }
  81. > db.products.find({{$or: {kcal:{$gte : 100}, category: "fruit"}})
  82. ... ;
  83. ... ^C
  84. > db.products.find({$or:[{kcal:{$gte : 100}, category: "fruit"}]})
  85. { "_id" : ObjectId("5542134e0cd6fe3ad7ecab75"), "name" : "banana", "kcal" : 143, "category" : "fruit", "eko" : 2 }
  86. > db.products.find({$or:[{kcal:{$gte : 100}}, category: "fruit"]})
  87. 2015-04-30T13:40:38.006+0200 E QUERY SyntaxError: Unexpected token :
  88. > db.products.find({$or:[kcal:{$gte : 100}, category: "fruit"]})
  89. 2015-04-30T13:40:45.341+0200 E QUERY SyntaxError: Unexpected token :
  90. > db.products.find({$or:[{kcal:{$gte : 100}}, {category: "fruit"}]})
  91. { "_id" : ObjectId("554210f80cd6fe3ad7ecab72"), "name" : "crisps", "kcal" : 460 }
  92. { "_id" : ObjectId("5542110a0cd6fe3ad7ecab73"), "name" : "chocolate", "kcal" : 511, "category" : "sweet" }
  93. { "_id" : ObjectId("554211160cd6fe3ad7ecab74"), "name" : "apple", "kcal" : 62.7, "category" : "fruit", "eko" : 2 }
  94. { "_id" : ObjectId("5542134e0cd6fe3ad7ecab75"), "name" : "banana", "kcal" : 143, "category" : "fruit", "eko" : 2 }
  95. > db.products.findOne({category:fruit})
  96. 2015-04-30T13:42:38.697+0200 E QUERY ReferenceError: fruit is not defined
  97. at (shell):1:31
  98. > db.products.findOne({category:"fruit"})
  99. {
  100. "_id" : ObjectId("554211160cd6fe3ad7ecab74"),
  101. "name" : "apple",
  102. "kcal" : 62.7,
  103. "category" : "fruit",
  104. "eko" : 2
  105. }
  106. > db.products.update({category:"fruit"},{$set: {tags: ["fruit", "diet", "eko"]}})
  107. WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
  108. > db.products.update({category:"fruit"},{$set: {tags: ["fruit", "diet", "eco"]}, {multi:true}})
  109. 2015-04-30T13:45:44.559+0200 E QUERY SyntaxError: Unexpected token {
  110. > db.products.update({category:"fruit"},{$set: {tags: ["fruit", "diet", "eco"]}, }, {multi:true})
  111. WriteResult({ "nMatched" : 2, "nUpserted" : 0, "nModified" : 2 })
  112. > db.products.update({name:"apple"},{$set: {tags: ["fruit", "diet", "eco", "fibre"]}, }, {multi:true})
  113. WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
  114. > db.products.find({$in:{tags: "fiber"}})
  115. Error: error: {
  116. "$err" : "Can't canonicalize query: BadValue unknown top level operator: $in",
  117. "code" : 17287
  118. }
  119. > db.products.find({tags:{$in: "fiber"}})
  120. Error: error: {
  121. "$err" : "Can't canonicalize query: BadValue $in needs an array",
  122. "code" : 17287
  123. }
  124. > db.products.find({tags:{$in: ["fiber]"}})
  125. ...
  126. ... db.products.find({tags:{$in: ["fiber]"}})
  127. ...
  128. ... ;
  129. ... db.products.find({tags:["fiber"]})
  130. ... db.products.find({ tags: ["fiber"]})
  131. ... db.products.find({tags:"fiber"})
  132. ... c^C
  133. > show collections
  134. category
  135. desserts
  136. products
  137. system.indexes
  138. > db.products.find({ tags: "fiber" })
  139. > db.products.find({ tags: ["fiber]" })
  140. ... c^C
  141. > db.products.find({ tags: ["fiber]" })
  142. ... ^C
  143. > db.products.find({ tags: ["fiber"] })
  144. > db.products.find({ tags: "eco" })
  145. { "_id" : ObjectId("554211160cd6fe3ad7ecab74"), "name" : "apple", "kcal" : 62.7, "category" : "fruit", "eko" : 2, "tags" : [ "fruit", "diet", "eco", "fibre" ] }
  146. { "_id" : ObjectId("5542134e0cd6fe3ad7ecab75"), "name" : "banana", "kcal" : 143, "category" : "fruit", "eko" : 2, "tags" : [ "fruit", "diet", "eco" ] }
  147. > db.products.find({ tags: ["fibre"] })
  148. > db.products.find({ tags: ["fibre"] })
  149. > db.products.find({ tags: "fibre" })
  150. { "_id" : ObjectId("554211160cd6fe3ad7ecab74"), "name" : "apple", "kcal" : 62.7, "category" : "fruit", "eko" : 2, "tags" : [ "fruit", "diet", "eco", "fibre" ] }
  151. > db.products.delete({category: "snacks"})
  152. 2015-04-30T13:53:37.614+0200 E QUERY TypeError: Property 'delete' of object khdb.products is not a function
  153. at (shell):1:19
  154. > db.products.remove({category: "snacks"})
  155. WriteResult({ "nRemoved" : 0 })
  156. > db.products.remove({category: "snack"})
  157. WriteResult({ "nRemoved" : 0 })
  158. > db.products.remove({category: "sweet"})
  159. WriteResult({ "nRemoved" : 1 })
  160. >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement