MongoMapper 保存不工作
不知道为什么这不起作用。这是我第一次使用 Mongo,但是从我读过的所有文档来看,这应该可行吗?有人知道我缺少什么吗?
require 'rubygems'
require 'sinatra/base'
require 'mongo_mapper'
mongo_server = '127.0.0.1'
mongo_database = 'inone'
MongoMapper.connection = Mongo::Connection.new(mongo_server)
MongoMapper.database = mongo_database
# DB model
class URLstore
include MongoMapper::Document
key :url_key, String
key :url, String
end
class URLnip < Sinatra::Base
get '/testmongo' do
nipurl = URLstore.new(:url_key => "abc", :url => "www.google.com")
nipurl.save
end
end
打开 Mongo 终端,我可以看到数据库已创建
> show dbs
inone 0.203125GB
,但这样做根本不会返回任何结果
> db.inone.find()
>
,或者
> db.inone.find({url : 'www.google.com'})
>
同样的事情不会返回任何结果。
No idea why this is not working. It's the first time I am working with Mongo, but from all the docs I have read, this should work? Anyone have any idea what I am missing?
require 'rubygems'
require 'sinatra/base'
require 'mongo_mapper'
mongo_server = '127.0.0.1'
mongo_database = 'inone'
MongoMapper.connection = Mongo::Connection.new(mongo_server)
MongoMapper.database = mongo_database
# DB model
class URLstore
include MongoMapper::Document
key :url_key, String
key :url, String
end
class URLnip < Sinatra::Base
get '/testmongo' do
nipurl = URLstore.new(:url_key => "abc", :url => "www.google.com")
nipurl.save
end
end
Opening the Mongo terminal I can see the DB get's created
> show dbs
inone 0.203125GB
but doing this brings back no results at all
> db.inone.find()
>
or
> db.inone.find({url : 'www.google.com'})
>
same thing nothing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
难道不应该是
db.urlstore.find()
吗?或者,MongoMapper
会改变这种情况。选择正确的数据库后,Mongo shell 中的show collections
会显示什么?Shouldn't that be
db.urlstore.find()
? Or howeverMongoMapper
changes the case. What doesshow collections
in a Mongo shell say after you select the right database?