MongoMapper无法保存文档的简单例子
我承认我对 Ruby 和现在的 mongoDB 还很陌生,所以我猜我在做一些愚蠢的事情。 对于测试,我有一段名为 tester.rb 的代码:
require 'Mongo_Mapper'
MongoMapper.database = "myTestDB"
class Person
include MongoMapper::Document
key :first_name, String
key :last_name, String
end
person = Person.new(:first_name => "FirstNameHere", :last_name => "LastNameHere")
person.save
我将毫无错误地运行该代码。 我跳到 mongoDB ....我的 myTestDB 已经创建了,是的!但如果我执行“db.myTestDB.find()”,我什么也看不到...... 我也尝试了“Person.create()”,但什么也没存储。
我不知道我做错了什么...... 想法?
谢谢
I'll admit I'm still new to Ruby and now mongoDB so i'm guessing i'm doing something dumb.
For a test I have this code called tester.rb:
require 'Mongo_Mapper'
MongoMapper.database = "myTestDB"
class Person
include MongoMapper::Document
key :first_name, String
key :last_name, String
end
person = Person.new(:first_name => "FirstNameHere", :last_name => "LastNameHere")
person.save
I'll run that code with no errors.
I jump over to mongoDB....my myTestDB has been created, yeah! But if i do "db.myTestDB.find()" I see nothing....
I tried "Person.create()" as well, nada...nothing stored.
I have no clue what I'm doing wrong....
ideas?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您在 mongodb 命令行中调用 find() 方法是错误的。
您可以通过运行以下命令来查看数据库中有哪些集合:
您应该看到类似以下内容:
如果您看到“people”集合,则可以运行:
以查看该集合中的所有记录。
希望这有帮助!
I think you're calling your find() method wrong in your mongodb command line.
You can see what collections are in your db by running:
You should see something like:
If you see the "people" collection, you can then run:
to see all of the records that are in that collection.
Hope this helps!