【发布时间】:2016-06-21 13:52:20
【问题描述】:
我有两个系列;用户和地址。地址集合与用户集合有关联。
module.exports = {
attributes: {
email: {
type: 'email',
required: true,
unique: true
},
cart: {
collection: 'cart',
via: 'user'
},
isAdmin : {
type : 'boolean',
defaultsTo : false
},
}
module.exports = {
attributes: {
user: {
model: 'user',
required: true
},
address: {
type: 'string',
},
addressAdditional: {
type: 'string',
},
city: {
type: 'string',
},
state: {
type: 'json',
},
zip: {
type: 'string',
},
}
我有从 UI 传递的 userId 和地址信息,我想更新地址集合。我尝试了以下 sn-p,但数据似乎没有更新。
var address = {
address: "123",
city: "Test City",
state: "NY",
zip: "12345"
};
User.findOne({user:userId}).then(function(model){
Address.update({id:model.id}, address)});
我做错了什么?谢谢
【问题讨论】:
-
地址集合中文档的字段“id”是否为“ObjectId”类型?如果是这样,请将此 id 转换为“ObjectId”。
标签: mongodb sails.js waterline