在客户端上测试文档上的过滤器 [英] Testing a filter on a document on client-side

查看:59
本文介绍了在客户端上测试文档上的过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个SON文档(通常使用mongodb查询来获取,但不是必须的),以及一个查询过滤器表达式(例如{ 'x': {'$ne': 5} }),是否有一种客户端方法来针对过滤器测试文档(使用pymongo)?

Say I have a SON-document (typically fetched using a mongodb query, but not necessarily), and a query-filter expression (e.g. { 'x': {'$ne': 5} }), is there a client-side way to test the document against the filter (using pymongo)?

预期的行为:

satisfies({ 'x': 1 }, { 'x': {'$ne': 5} })
=> True
satisfies({ 'x': 5 }, { 'x': {'$ne': 5} })
=> False

推荐答案

我发现了这个有趣的 mongomock 项目

I found this interesting mongomock project.

filter_applies()函数似乎就是这样.

The filter_applies() functions seems to be it.

def filter_applies(search_filter, document):
    """
    This function implements MongoDB's matching strategy over documents in the find()
    method and other related scenarios (like $elemMatch)
    """
    ...

这篇关于在客户端上测试文档上的过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆