さて、私はサブドキュメント(埋め込みドキュメント)をMongooseで更新しようとしています。私は持っています:
query =
'fanclubs.fanclub_id': fanclub_id
fan_update =
'fanclubs.$.fanclub_name': fanclub_data.fanclub_name
Fan.update query, fan_update, (err, numAffected) ->
console.log err
console.log numAffected
Fan
オブジェクトを新しいで実際に更新していないようですfanclub_name
。アイデア?
fanclub_name
フィールドを更新したい
スキーマを編集Fan
する
mongoose = require "mongoose"
{FanClubMemberSchema} = require './schemas/fanClubMemberSchema'
validation = require './validation'
FanSchema = new mongoose.Schema(
first_name:
type: String
trim: true
required: true
last_name:
type: String
trim: true
required: true
fullname:
type: String
trim: true
required: true
email:
type: String
lowercase: true
unique: true
required: true
validate: [validation.email, 'Email is invalid']
fanclubs:
type: [FanClubMemberSchema]
required: false
added_on:
type: Date
default: Date.now
required: true
)
FanClubMemberSchema
mongoose = require "mongoose"
FanClubMemberSchema = new mongoose.Schema
fanclub_id:
type: String
trim: true
required: true
fanclub_name:
type: String
trim: true
required: true
fanclub_image:
type: String
trim:true
required:true
access:
type: String
trim: true
required: true
joinedOn:
type: Date
default: Date.now
required: true
exports.FanClubMemberSchema = FanClubMemberSchema