haskell - Haskell 是否支持 MongoDB 的查询运算符,例如 "$in"?

标签 haskell mongodb-query

要检索一组文档,其特定字段(例如作者)是一组值中的任意一个,haskell 的 mongodb 是如何做到的?因为这对我来说并不明显。 感谢您的任何提示和帮助!

最佳答案

如果您使用mongoDB包,然后注意它接受任意文档作为 Selector 。因此,您可以自由使用 mongodb 支持的任何内容,包括 $in:

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ExtendedDefaultRules #-}

import Database.MongoDB
import Control.Monad.IO.Class (liftIO)

main = do
  pipe <- runIOE $ connect $ host "127.0.0.1"
  e <- access pipe master "testdb" $ do
    insertMany "test" [
      ["i" =: 1, "name" =: "Name1"],
      ["i" =: 2, "name" =: "Name2"],
      ["i" =: 3, "name" =: "Name3"]
      ]
    rest =<< find (select ["i" =: ["$in" =: [1, 3]]] "test")
  close pipe
  print e

输出:

Right [[ _id: 52a9ea3008d0cf401e000000, i: 1, name: "Name1"],[ _id: 52a9ea3008d0cf401e000002, i: 3, name: "Name3"]]

使用 haskell 和 mongodb 快乐黑客:)

关于haskell - Haskell 是否支持 MongoDB 的查询运算符,例如 "$in"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20548517/

相关文章:

haskell - 代表性双仿函数的不动点

python - 根据时间戳选择并用零更新时间戳

mongoDB - 基于返回结果数量的不同查询条件

arrays - MongoDB统计最常见的嵌套数组

mongodb - 什么是 MongoDB 中的光标?

mongodb - 如何在 MongoDB 中使用深度查询获取 `find()` 数据?

haskell - 以冒号开头的运算符符号是构造函数

file - 如何在 Yesod 中为静态文件启用 'Access-Control-Allow-Origin' header ?

haskell - 懒惰的字节串 : memory exploding in certain cases

haskell - 什么 Haskell 包有单位仿函数/monad?