Java – MongoDB查询的BSON过滤器

huangapple 未分类评论70阅读模式
英文:

Java - bson filter for mongodb query

问题

Sure, here's the translation of the provided content:

我正在尝试在我的Java后端创建一个过滤器。我的文档如下:

    {
    "_id" : ObjectId("abcdefg"),
    "active" : false,
    "externalId" : "332",
    "link" : "mylink",
    "owner" : {
        "sourceValue" : {
            "externalId" : "0000",
            "familyName" : "jobs",
            "givenName" : "ben",
            "username" : "bjobs"
        }
    },
    "title" : "title",
    "tool" : "app",
    "hidden" : false,
    "accessable" : false
    }

使用这段代码,我可以获取一个`owner`的所有文档:

      private Bson ownerFilter(String username) {
    return orNonNull(
        andNonNull(
            exists("owner.overrideValue", false), eq("owner.sourceValue.username", ntAccount)),
        eq("owner.overrideValue.username", username));
    }

非常好!现在我要添加什么,才能仅获取那些`"active" : true`的文档呢?

谢谢!

请注意,我只返回了翻译好的部分,没有包含其他内容。

英文:

I'm trying to create a filter in my java backend. My document looks like this:

{
"_id" : ObjectId("abcdefg"),
"active" : false,
"externalId" : "332",
"link" : "mylink",
"owner" : {
    "sourceValue" : {
        "externalId" : "0000",
        "familyName" : "jobs",
        "givenName" : "ben",
        "username" : "bjobs"
    }
},
"title" : "title",
"tool" : "app",
"hidden" : false,
"accessable" : false
}

With this code, I'm able to get all documents for one owner:

  private Bson ownerFilter(String username) {
return orNonNull(
    andNonNull(
        exists("owner.overrideValue", false), eq("owner.sourceValue.username", ntAccount)),
    eq("owner.overrideValue.username", username));
}

which is good! What do I have to add now that I get only these documents, where "active" : true?

Thank you!

huangapple
  • 本文由 发表于 2020年8月14日 19:46:07
  • 转载请务必保留本文链接:https://java.coder-hub.com/63412156.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定