只有当它丢失时才插入mongo文档字段

时间:2016-02-17 18:53:09

标签: mongodb

新手问题:

我之前创建了一个mongo集合。最近插入了一些文档但结构略有变化 - 只添加了新字段。现在,我想返回并使用默认值的新字段更新旧文档。怎么样?

示例:

data Settings = Settings
   { sVerbose     :: Bool
   , sFileTitle   :: Bool
   , sSource      :: FilePath
   , sDestination :: FilePath
   }

settingsP :: Parser Settings
settingsP = 
  Settings <$> switch "verbose"   'v' "Be more verbose"
           <*> switch "filetitle" 'f' "..."
           <*> argPath "src" "Source directory"
           <*> argPath "dest" "Destination directory"

description :: Description
description = "Description of your program"

main = do
  (Settings verbose filetitle source dest) <- options description settingsP
  ...

如何使用&#34; z&#34;更新前两个文档?零值?

1 个答案:

答案 0 :(得分:3)

在更新中使用$set运算符,查询查找没有z字段的文档(使用$exists运算符)。以下更新运算符 证明了这一点:

#Configuration for Health endpoint
endpoints.health.id=health
endpoints.health.path=/ping/me
endpoints.health.enabled=true
endpoints.health.sensitive=false

#Manage endpoints
management.port=9000
management.health.diskspace.enabled=false