checking mongo database for data
Posted
by
user1647484
on Stack Overflow
See other posts from Stack Overflow
or by user1647484
Published on 2012-09-17T03:31:47Z
Indexed on
2012/09/17
3:37 UTC
Read the original article
Hit count: 206
mongodb
I'm playing around with this tutorial that uses Sinatra, backbone.js, and mongodb for the database. It's my first time using mongo. As far as I understand it the app uses both local storage and a database. it has these routes for the database. For example, it has these routes
get '/api/:thing' do
DB.collection(params[:thing]).find.to_a.map{|t| from_bson_id(t)}.to_json
end
get '/api/:thing/:id' do
from_bson_id(DB.collection(params[:thing]).find_one(to_bson_id(params[:id]))).to_json
end
post '/api/:thing' do
oid = DB.collection(params[:thing]).insert(JSON.parse(request.body.read.to_s))
"{\"_id\": \"#{oid.to_s}\"}"
end
After turning the server off and then on, I could see in the server getting data from the database routes
127.0.0.1 - - [17/Sep/2012 08:21:58] "GET /api/todos HTTP/1.1" 200 430 0.0033
My question is, how can I check from within the mongo shell whether the data's in the database?
I started the mongo shell
./bin/mongo
I selected the database 'use mydb'
and then looking at the docs (http://www.mongodb.org/display/DOCS/Tutorial) I tried commands such as
> var cursor = db.things.find();
> while (cursor.hasNext()) printjson(cursor.next());
but they didn't return anything.
© Stack Overflow or respective owner