【发布时间】:2012-08-30 21:48:02
【问题描述】:
要明确这个问题与从数据库加载数据有关,而不是更新数据库中的文档。
使用以下架构:
new mongoose.Schema
name: String
code:
type: String
index:
unique: true
_contacts: [
type: mongoose.Schema.Types.ObjectId
ref: 'Person'
]
我已经像这样创建了我的文档:
client = new Client code:'test',name:'test competition',contacts:[]
client.save()
在应用程序的其他地方或通过 API 调用,它不能轻易引用上面缓存的版本:
Client.findOne(code:'test').exec (err,client) ->
return if err or not client
client._contacts.push person.id # person has come from somewhere
client.save (err) ->
return err if err
如果我们返回到我们原来的 client 对象,我想知道是否有办法为整个文档或仅针对特定路径刷新该对象。比如;
client.refresh '_contacts', (err) ->
return err if err
或者最好只维护一个全局引用的对象?
【问题讨论】: