Ich habe zwei Sammlungen; Benutzer und Adresse. Die Adresssammlung ist mit der Benutzersammlung verknüpft.Sailsjs Update-Modell Mongodb
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',
},
}
Ich habe die userId und Adressinformationen von der Benutzeroberfläche übergeben und ich möchte die Adresssammlung aktualisieren. Ich habe das folgende Snippet ausprobiert, aber es scheint nicht so, als ob die Daten aktualisiert werden.
var address = {
address: "123",
city: "Test City",
state: "NY",
zip: "12345"
};
User.findOne({user:userId}).then(function(model){
Address.update({id:model.id}, address)});
Was mache ich falsch? Danke
Ist das Feld 'id' eines Dokuments in der Adresssammlung ein 'ObjectId' Typ? Wenn ja, wandle diese ID in eine 'ObjectId' um. – Kevin