英文:
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!
专注分享java语言的经验与见解,让所有开发者获益!
评论