Created
June 4, 2015 12:23
-
-
Save darui00kara/93c9b1bd648bf4e9806f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mongo = Mongo.connect! | |
db = mongo |> Mongo.db("phoenix_bbs") | |
collection = db |> Mongo.Db.collection("comments") | |
# init data | |
Mongo.Collection.drop collection | |
[ | |
%{name: "hoge", title: "hoge", comment: "hogehoge"}, | |
%{name: "huge", title: "huge", comment: "hugehuge"}, | |
%{name: "darui", title: "blogger", comment: "darui"} | |
] |> Mongo.Collection.insert(collection) | |
IO.puts "insert result" | |
%{name: "foo", title: "bar", comment: "foobar"} |> Mongo.Collection.insert_one!(collection) | |
# find | |
docs = collection |> Mongo.Collection.find |> Enum.to_list | |
IO.inspect docs | |
IO.puts "" | |
IO.puts "update result" | |
collection |> Mongo.Collection.update(%{name: "foo"}, %{name: "fizz", title: "bazz", comment: "fizzbazz"}) | |
# find | |
docs = collection |> Mongo.Collection.find |> Enum.to_list | |
IO.inspect docs | |
IO.puts "" | |
IO.puts "delete result" | |
collection |> Mongo.Collection.delete(%{name: "fizz"}) | |
# find | |
docs = collection |> Mongo.Collection.find |> Enum.to_list | |
IO.inspect docs | |
Mongo.Server.close(mongo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment