我有这样的数据
Mywants:[
{"title":"lap","rate":$20}
{"title":"lap","rate":$20}
{"title":"lap","rate":$20}
]
如果我将新数据保存到数组(mywant)中,我应该使用新的唯一 ID 保存,那么如何使用 javascript 进行保存。所以它应该看起来像:
Mywants:[
{"title":"lap","rate":$20,_id:objectId("512640f3243c837c0e0004401}
{"title":"lap","rate":$20,_id:objectId("512640f3243c837254000001}
{"title":"lap","rate":$20,_id:objectId("512640f3243c8372540257001}}
]
要插入我正在使用类似的命令
collection.update({"userid":1248787885},{$push:{"Mywant":{"title":"car","rate":$100}}});