首页 \ 问答 \ MongoDB部分匹配对象(MongoDB partial match on object)

MongoDB部分匹配对象(MongoDB partial match on object)

我试图在MongoDB中编写一个查询,根据字段是否部分匹配给定对象来提取某些对象。

我的MongoDB集合中的对象与此类似:

  {
    permissions: {
      records: [
        "add",
      ]
    }
  }

我希望能够通过查询给定用户的权限来检索相关对象。

例如,如果我查询了以下对象:

  {
    permissions: {
      records: [
        "add",
        "delete"
      ],
      folders: [
        "delete",
      ]
    }
  }

我想要返回与查询对象部分匹配的集合中的对象,这可能是这样的:

  {
    permissions: {
      records: [
        "add",
      ]
    }
  },
  {
    permissions: {
      records: [
        "delete",
      ],
      folders: [
        "delete",
      ]
    }
  }

如果有人可以给我任何指导,这将非常感谢!


I'm trying to write a query in MongoDB to pull out certain objects based on whether a field partially matches a given object.

The objects in my MongoDB collection look something similar to this:

  {
    permissions: {
      records: [
        "add",
      ]
    }
  }

I'd like to be able to retrieve the relevant objects by querying on the permissions of a given user.

For example, if I queried with the following object:

  {
    permissions: {
      records: [
        "add",
        "delete"
      ],
      folders: [
        "delete",
      ]
    }
  }

I'd want to return back the objects from the collection that partially matched the queried object, which would perhaps be these:

  {
    permissions: {
      records: [
        "add",
      ]
    }
  },
  {
    permissions: {
      records: [
        "delete",
      ],
      folders: [
        "delete",
      ]
    }
  }

If anyone could give me any guidance on this, that'd be much appreciated!


原文:https://stackoverflow.com/questions/48148992
更新时间:2021-08-11 17:08

最满意答案

这不是我以前的修复类型,但事情似乎按预期工作,所以此时我只需要发货。

首先,事实证明我们的应用程序的旧版本正在请求offline_access。 我不知道。 我进入了我的FB应用程序的设置>高级,并启用了“删除offline_access权限”。 我现在正在取回持续两个月的令牌( 查看facbeook令牌调试器 )。

现在我已经找回了正确的标记类型,但在取消激活/过期时仍然有问题。 由于我现在正在取回2个月的令牌,因此我迫不及待地要过期,所以我的计划是通过进入我的帐户设置并取消授权来触发OAuthException。

在我的appDidBecomeActive中,我把[FBRequestConnection startForMeWithCompletionHandler:nil]简单地触发一个静默请求给FB,当它由于一个无效的会话/令牌而失败时,代码流将通过正确的路径运行,[FBSession renewSystemAuthorization]最终会被调用,这是我最需要的。 下次我通过FB登录到我的应用程序时,iOS允许我做的是,iOS再次提示我,理解我没有有效的标记了。 调用[FBSession renewSystemAuthorization]有效地告诉iOS,当我的应用程序下次请求访问时,打开Facebook并给我一个新的/刷新的令牌。

大多数情况下,一切正如预期的那样工作。


This isn't the type of fix I was after, but things look to be working as expected, so at this point I just need to ship.

First things first, it turns out that old versions of our app were requesting offline_access. I did not know that. I went in to my FB app's Settings > Advanced, and enabled "Remove offline_access permission." I am now getting back a token that lasts two months (check out the facbeook token debugger).

Now that I'm getting back the correct kind of token, I still have a problem with getting back a valid token when it has been deactivated/expired. Since I'm now getting back a 2 month token, I can't wait for that to expire, so my plan was to trigger an OAuthException by going into my account's settings and deauthorizing it.

In my appDidBecomeActive, I put [FBRequestConnection startForMeWithCompletionHandler:nil] to simply trigger a silent request to FB, and when that fails because of an invalid session/token, the code flow runs through the correct path and [FBSession renewSystemAuthorization] ends up getting called, which is ultimately what I was needing. What this allows iOS to do is the next time I go to Log in to my app through FB, iOS prompts me again, understanding I don't have a valid token anymore. Calling [FBSession renewSystemAuthorization] effectively tells iOS that the next time my app requests access, hit facebook and give me back a new/refreshed token.

For the most part everything is working as expected now.

相关问答

更多
  • 你可以使用委托方法: - (void)fbDialogLogin:(NSString *)token expirationDate:(NSDate *)expirationDate 有关更多信息,您可以参考以下问题: Facebook访问令牌 You can use delegate method: - (void)fbDialogLogin:(NSString *)token expirationDate:(NSDate *)expirationDate for more information ...
  • Facebook iOS SDK项目最近的一次提交包括一个“扩展访问令牌”方法,用于扩展过期的令牌。 有关这方面的更多信息以及弃用“offline_access”的信息,请参见Facebook开发人员的博客文章 。 A recent commit in the Facebook iOS SDK project included an "extend access token" method for extending an expired token. More information about this ...
  • 这不是我以前的修复类型,但事情似乎按预期工作,所以此时我只需要发货。 首先,事实证明我们的应用程序的旧版本正在请求offline_access。 我不知道。 我进入了我的FB应用程序的设置>高级,并启用了“删除offline_access权限”。 我现在正在取回持续两个月的令牌( 查看facbeook令牌调试器 )。 现在我已经找回了正确的标记类型,但在取消激活/过期时仍然有问题。 由于我现在正在取回2个月的令牌,因此我迫不及待地要过期,所以我的计划是通过进入我的帐户设置并取消授权来触发OAuthExcep ...
  • 我将详细提到我所知道的最佳实践。 服务器具有Facebook应用程序ID(当您注册新应用程序时从Facebook提供的应用程序的特殊ID)。 您为服务器发送FBSDKAccessToken,服务器将使用app id作为密钥加密FBSDKAccessToken,并返回名为“AccessKey”的结果。 保存accesskey并从现在开始将其用作与服务器的关系。 这样,没有人可以知道userFBID,因为你加密了它,你没有分享你的Facebook应用程序ID,因为它应该是一个秘密。 希望这可以帮助! I wil ...
  • 根据Facebook( https://developers.facebook.com/docs/apps/changelog ),他们的API v2.0删除了对xmpp_login权限的访问权限,这就是它无法正常工作的原因。 一个快速的解决方法是强制较新的SDK使用API的v1.0。 [FBSettings enablePlatformCompatibility:YES]; API v1.0将于2015年4月15日前发布,facebook将声明如下: Apps that were inactive or ...
  • 它使本地令牌无效(即在实际的客户端设备或浏览器上),但令牌本身仍然有效。 如果存储访问令牌服务器端,您仍然可以使用它。 It invalidates the tokens locally (i.e. on the actual client device or browser), but the token itself is still valid. If you store the access token server side, you can still use it.
  • 如果您使用SDK的当前版本(此时为v3.2.1),则可以通过以下方式访问用户的访问令牌: [[[FBSession activeSession] accessTokenData] accessToken] If you're using the current version (v3.2.1 at this time) of the SDK you can get to the user's access token with the following: [[[FBSession activeSessio ...
  • 编辑4/05/2018 Facebook已修复它。 Facebook回复: 感谢您的联系。 这实际上是我们已经在另一个错误报告中跟踪的已知问题。 我要将您的报告与现有报告合并,因此我们可以在一个地方处理该问题。 请参阅此主题以获取更新: http : //developers.facebook.com/bugs/194772814474841/ 希望我们今天能从FB获得更新。 EDIT 4/05/2018 Facebook have fix it. facebook responses: Thanks fo ...
  • 在嗅探数据包之后,我们意识到Facebook现在使用Safari Web View,而不是通过App开放,Facebook正在使用Safari上另一个帐户的旧缓存会话。 愚蠢的错误 - 但新的Facebook SDK也很奇怪。 希望这有助于其他人。 After sniffing the packets we realized now that Facebook uses the Safari Web View, instead of opening up via App, Facebook was usin ...
  • 事实证明我的appDelegate中存在一个问题,我在那里设置了自定义视图控制器。 我还原了代码以使用故事板,问题得到了解决 - 对于有类似问题的人来说,这本身并不是解决方案,但这对我来说已经足够了。 It turns out that there was a problem in my appDelegate where I was setting up a custom View Controller. I reverted the code to use storyboards and the iss ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。