从 mongoDB 中删除文档 [英] Delete document from mongoDB
问题描述
这可能是一个非常愚蠢的问题,但我是 MongoDB 的新手,所以请耐心等待.我创建了一个独立的 ruby 类:
This might be a really stupid question, but I'm new to MongoDB, so bear with me. I've created a stand alone ruby class:
require 'rubygems'
require 'mongo'
require 'bson'
require 'mongo_mapper'
MongoMapper.database = "testing"
class Twit
include MongoMapper::Document
key :id, Integer, :unique => true
key :screen_name, String, :unique => true
...
然后我用 irb 执行以下操作
Then I do the following with irb
>> twit = Twit.all.first
=> #<Twit _id: BSON::ObjectId('4df2d4a0c251b2754c000001'), id: 21070755, screen_name: "bguestSB">
>> twit.destroy
=> true
>> Twit.all
=> [#<Twit _id: BSON::ObjectId('4df2d4a0c251b2754c000001'), id: 21070755, screen_name: "bguestSB">]
那么如何销毁MongoDB中的文档呢?我做错了什么?
So how do I destroy documents in MongoDB? What am I doing wrong?
推荐答案
感谢大家对这个问题的帮助.对于其他遇到此问题的人,我相信这是因为我忘记将 mongodb 二进制文件的位置添加到 $PATH
变量
Thanks for all the help on this issue. For anyone else who has this problem, I believe it is because I forgot to add the the location of the mongodb binary files to the $PATH
variable
在我的情况下,在 /usr/local/mongodb/bin
中安装了二进制文件,因此我需要添加 export PATH=/usr/local/mongodb/bin:$PATH
到我的 ~/.bash_profile
In my case installed the binary files in /usr/local/mongodb/bin
as such I needed to add export PATH=/usr/local/mongodb/bin:$PATH
to my ~/.bash_profile
这篇关于从 mongoDB 中删除文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!