1
我想創建一個查詢,以滿足以下條件:Mongoose如何查詢多個文檔,如果找不到,並返回id?
- 搜索與集合中指定名稱的文件。
- 如果集合中不存在具有指定名稱的文檔,請創建新文檔。
- 返回文檔的.id,或者它們是新保存的。
如何在不使用for循環的情況下實現此目的?
var tagArr = req.body.tags.join()
Tag.find({tagName: {$in: tagArr}}, function(err, docs){
// find the tag._ids by tagNames
// if tag not found, create a tag
// return old and new tag_ids with the tagNames
}