Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use khdb
- switched to db khdb
- > db.desserts.insert({name: "salad", price: 15.50})
- ^[[A^[[A^[[A^[[AWriteResult({ "nInserted" : 1 })
- > db.desserts.insert({name: "milkshake", price: 8.50, discount: 2})
- WriteResult({ "nInserted" : 1 })
- > db.desserts.insert({name: "cake", price: 6.50})
- WriteResult({ "nInserted" : 1 })
- > db.category.insert({name:"food"})
- WriteResult({ "nInserted" : 1 })
- > db.category.insert({name:"snack"})
- WriteResult({ "nInserted" : 1 })
- > db.category.insert({name:"sweet"})
- WriteResult({ "nInserted" : 1 })
- > db.category.insert({name:"fruit"})
- WriteResult({ "nInserted" : 1 })
- > db.products.insert({name:"bread", kcal: 70})
- WriteResult({ "nInserted" : 1 })
- > khdb.product.insert({name: "banana", price: 2.50})
- 2015-04-30T13:24:25.190+0200 E QUERY ReferenceError: khdb is not defined
- at (shell):1:1
- > db.products.insert({name:"crisps", kcal: 460})
- WriteResult({ "nInserted" : 1 })
- > db.products.insert({name:"chocolate", kcal: 511})
- WriteResult({ "nInserted" : 1 })
- > db.products.insert({name:"apple", kcal: 60})
- WriteResult({ "nInserted" : 1 })
- > db.desserts.update({$mul: {price: 0.95}})
- 2015-04-30T13:27:30.423+0200 E QUERY Error: need an object
- at Error (<anonymous>)
- at DBCollection._parseUpdate (src/mongo/shell/collection.js:400:21)
- at DBCollection.update (src/mongo/shell/collection.js:432:23)
- at (shell):1:13 at src/mongo/shell/collection.js:400
- > db.desserts.update({name: "salad"},{$mul: {price: 0.95}})
- WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
- > db.desserts.update({},{$mul: {price: 0.95}})
- WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
- > db.desserts.update({},{$mul: {price: 0.95}})
- WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
- > db.desserts.update({},{$mul: {price: 0.95}}, {multi:true})
- WriteResult({ "nMatched" : 3, "nUpserted" : 0, "nModified" : 3 })
- > db.desserts.update({category:"fruit"},{$mul: {kcal: 0.95}}, {multi:true})
- WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })
- > db.products.update({category:"fruit"},{$mul: {kcal: 0.95}}, {multi:true})
- WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })
- > db.products.update({name: "bread"}, {$set: {category: "food"}})
- WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
- > db.products.update({name: "apple"}, {$set: {category: "fruit"}})
- WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
- > db.products.update({name: "banana"}, {$set: {category: "fruit"}})
- WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })
- > db.products.update({name: "chocolate"}, {$set: {category: "sweet"}})
- WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
- > db.desserts.update({category:"fruit"},{$mul: {kcal: 0.95}}, {multi:true})
- WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })
- > db.products.update({name: "chocolate"}, {$set: {category: "sweet"}})
- WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })
- > db.products.update({category:"fruit"},{$mul: {kcal: 0.95}}, {multi:true})
- WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
- > db.products.insert({name:"banana", kcal: 130, category: "fruit"})
- WriteResult({ "nInserted" : 1 })
- > db.products.update({category:"fruit"},{$mul: {kcal: 1.1}}, {multi:true})
- WriteResult({ "nMatched" : 2, "nUpserted" : 0, "nModified" : 2 })
- > db.products.count()
- 5
- > db.desserts.count()
- 3
- > db.products.update({category:"fruit"},{$set: {eko: 2}}, {multi:true})
- WriteResult({ "nMatched" : 2, "nUpserted" : 0, "nModified" : 2 })
- > db.products.find({kcal:{$gte : 100}})
- { "_id" : ObjectId("554210f80cd6fe3ad7ecab72"), "name" : "crisps", "kcal" : 460 }
- { "_id" : ObjectId("5542110a0cd6fe3ad7ecab73"), "name" : "chocolate", "kcal" : 511, "category" : "sweet" }
- { "_id" : ObjectId("5542134e0cd6fe3ad7ecab75"), "name" : "banana", "kcal" : 143, "category" : "fruit", "eko" : 2 }
- > db.products.find({kcal:{$gte : 100, category: "fruit"}})
- Error: error: {
- "$err" : "Can't canonicalize query: BadValue unknown operator: category",
- "code" : 17287
- }
- > db.products.find({kcal:{$gte : 100}, category: "fruit"})
- { "_id" : ObjectId("5542134e0cd6fe3ad7ecab75"), "name" : "banana", "kcal" : 143, "category" : "fruit", "eko" : 2 }
- > db.products.find({{$or: {kcal:{$gte : 100}, category: "fruit"}})
- ... ;
- ... ^C
- > db.products.find({$or:[{kcal:{$gte : 100}, category: "fruit"}]})
- { "_id" : ObjectId("5542134e0cd6fe3ad7ecab75"), "name" : "banana", "kcal" : 143, "category" : "fruit", "eko" : 2 }
- > db.products.find({$or:[{kcal:{$gte : 100}}, category: "fruit"]})
- 2015-04-30T13:40:38.006+0200 E QUERY SyntaxError: Unexpected token :
- > db.products.find({$or:[kcal:{$gte : 100}, category: "fruit"]})
- 2015-04-30T13:40:45.341+0200 E QUERY SyntaxError: Unexpected token :
- > db.products.find({$or:[{kcal:{$gte : 100}}, {category: "fruit"}]})
- { "_id" : ObjectId("554210f80cd6fe3ad7ecab72"), "name" : "crisps", "kcal" : 460 }
- { "_id" : ObjectId("5542110a0cd6fe3ad7ecab73"), "name" : "chocolate", "kcal" : 511, "category" : "sweet" }
- { "_id" : ObjectId("554211160cd6fe3ad7ecab74"), "name" : "apple", "kcal" : 62.7, "category" : "fruit", "eko" : 2 }
- { "_id" : ObjectId("5542134e0cd6fe3ad7ecab75"), "name" : "banana", "kcal" : 143, "category" : "fruit", "eko" : 2 }
- > db.products.findOne({category:fruit})
- 2015-04-30T13:42:38.697+0200 E QUERY ReferenceError: fruit is not defined
- at (shell):1:31
- > db.products.findOne({category:"fruit"})
- {
- "_id" : ObjectId("554211160cd6fe3ad7ecab74"),
- "name" : "apple",
- "kcal" : 62.7,
- "category" : "fruit",
- "eko" : 2
- }
- > db.products.update({category:"fruit"},{$set: {tags: ["fruit", "diet", "eko"]}})
- WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
- > db.products.update({category:"fruit"},{$set: {tags: ["fruit", "diet", "eco"]}, {multi:true}})
- 2015-04-30T13:45:44.559+0200 E QUERY SyntaxError: Unexpected token {
- > db.products.update({category:"fruit"},{$set: {tags: ["fruit", "diet", "eco"]}, }, {multi:true})
- WriteResult({ "nMatched" : 2, "nUpserted" : 0, "nModified" : 2 })
- > db.products.update({name:"apple"},{$set: {tags: ["fruit", "diet", "eco", "fibre"]}, }, {multi:true})
- WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
- > db.products.find({$in:{tags: "fiber"}})
- Error: error: {
- "$err" : "Can't canonicalize query: BadValue unknown top level operator: $in",
- "code" : 17287
- }
- > db.products.find({tags:{$in: "fiber"}})
- Error: error: {
- "$err" : "Can't canonicalize query: BadValue $in needs an array",
- "code" : 17287
- }
- > db.products.find({tags:{$in: ["fiber]"}})
- ...
- ... db.products.find({tags:{$in: ["fiber]"}})
- ...
- ... ;
- ... db.products.find({tags:["fiber"]})
- ... db.products.find({ tags: ["fiber"]})
- ... db.products.find({tags:"fiber"})
- ... c^C
- > show collections
- category
- desserts
- products
- system.indexes
- > db.products.find({ tags: "fiber" })
- > db.products.find({ tags: ["fiber]" })
- ... c^C
- > db.products.find({ tags: ["fiber]" })
- ... ^C
- > db.products.find({ tags: ["fiber"] })
- > db.products.find({ tags: "eco" })
- { "_id" : ObjectId("554211160cd6fe3ad7ecab74"), "name" : "apple", "kcal" : 62.7, "category" : "fruit", "eko" : 2, "tags" : [ "fruit", "diet", "eco", "fibre" ] }
- { "_id" : ObjectId("5542134e0cd6fe3ad7ecab75"), "name" : "banana", "kcal" : 143, "category" : "fruit", "eko" : 2, "tags" : [ "fruit", "diet", "eco" ] }
- > db.products.find({ tags: ["fibre"] })
- > db.products.find({ tags: ["fibre"] })
- > db.products.find({ tags: "fibre" })
- { "_id" : ObjectId("554211160cd6fe3ad7ecab74"), "name" : "apple", "kcal" : 62.7, "category" : "fruit", "eko" : 2, "tags" : [ "fruit", "diet", "eco", "fibre" ] }
- > db.products.delete({category: "snacks"})
- 2015-04-30T13:53:37.614+0200 E QUERY TypeError: Property 'delete' of object khdb.products is not a function
- at (shell):1:19
- > db.products.remove({category: "snacks"})
- WriteResult({ "nRemoved" : 0 })
- > db.products.remove({category: "snack"})
- WriteResult({ "nRemoved" : 0 })
- > db.products.remove({category: "sweet"})
- WriteResult({ "nRemoved" : 1 })
- >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement