【发布时间】:2016-02-04 11:35:13
【问题描述】:
我们可以更新子文档数组字段以及 Mgo 中的其他文档字段吗? 如果是这样,请帮助我解决我的问题。
c := db.C("user")
colQuerier := bson.M{"email": *olduname}
change := bson.M{"$set":bson.M{"password":*pwd, "place":*place, "emails.$.received":*received,"emails.$.sent":*sent}}
err := c.Update(colQuerier, change)
我的数据库结构如下:
type Emails struct{
Id bson.ObjectId `bson:"_id,omitempty"`
Received string
Sent string
}
type User struct {
Id bson.ObjectId `bson:"_id,omitempty"`
Email string
Password string
Place string
Emails
}
我收到一个运行时错误消息:位置运算符未从查询中找到所需的匹配项。未扩展的更新:电子邮件.$.received
【问题讨论】: