【发布时间】:2015-04-23 07:38:07
【问题描述】:
我正在尝试删除一堆具有共同属性的文档。这是一个文档的样子:
{
_id : {
attr1 : 'foo',
attr2 : 'bar'
},
attr3 : 'baz',
}
多个文档将在 attr1 条目中具有相同的 'foo' 值。我正在尝试删除所有这些。为此,我有类似的东西:
type DocId struct {
Attr1 string `bson:"attr1,omitempty"`
Attr2 string `bson:"attr2,omitempty"`
}
type Doc struct {
Id DocId `bson:"_id,omitempty"`
Attr3 string `bson:"attr3,omitempty"`
}
doc := Doc{
Id : DocId{ Attr1 : 'foo' },
}
collection := session.DB("db").C("collection")
collection.Remove(doc)
这里的问题是我在删除调用中收到Not found 错误。
你能看出代码中有什么奇怪的地方吗?
非常感谢!
【问题讨论】:
-
好吧,我在代码中看到的一件奇怪的事情是它无法编译,因为
'foo'导致语法错误。 -
Not found可能是集合名称拼错的结果,或者您没有任何符合条件的文档(例如,您拼错了属性值,或者您已经删除了所有可能匹配它)。你能确认这些不是吗? -
@rightfold,你可以猜到,这只是一个你不需要执行的例子;)
-
@icza,我已经检查过了。我正在查询具有匹配条件的正确集合:)
标签: mongodb go attributes partial mgo