Skip to content

Commit c878c36

Browse files
author
Seiichi Yonezawa
committed
Update database/mongo.md
* collections return as JSON * return false if object does not exist
1 parent 5796373 commit c878c36

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

databases/mongo.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ your Mongo instance.
4040

4141
```ruby
4242
get '/collections/?' do
43-
settings.mongo_db.collection_names
43+
content_type :json
44+
settings.mongo_db.collection_names.to_json
4445
end
4546

4647
helpers do
@@ -117,9 +118,14 @@ end
117118
# delete the specified document and return success
118119
delete '/remove/:id' do
119120
content_type :json
120-
settings.mongo_db['test'].
121-
remove(:_id => object_id(params[:id]))
122-
{:success => true}.to_json
121+
db = settings.mongo_db['test']
122+
id = object_id(params[:id])
123+
if db.find_one(id)
124+
db.remove(:_id => id)
125+
{:success => true}.to_json
126+
else
127+
{:success => false}.to_json
128+
end
123129
end
124130
```
125131

0 commit comments

Comments
 (0)