和+或+正则表达式查询在python中使用mongoDB

时间:2018-07-20 15:33:48

标签: python regex mongodb

我在MongoDB中有文档列表,其中任务正在与用户(多个用户)挂起,任务基本上可以由用户委派给用户。如果该特定用户登录(USER0),我必须显示他/她待处理的任务列表。

文档中的样本数据

"task_number": 2458
"from_system": "ETS"
"ticket_name": "Visiting Card"
"category_id": 4
"status_id": 53
"created_for": "ABCD"
"created_date": "23rd May 2018 08:20"
"assigned_to": "None"
"pending_approval_with": "USER0"
"delegated_to": "USER1"

"task_number": 2457
"from_system": "ETS"
"ticket_name": "Visiting Card"
"category_id": 4
"status_id": 53
"created_for": "ABCD"
"created_date": "23rd May 2018 08:20"
"assigned_to": "None"
"pending_approval_with": ", USER10, USER0"
"delegated_to": "USER1"

"task_number": 2456
"from_system": "ETS"
"ticket_name": "Visiting Card"
"category_id": 4
"status_id": 54
"created_for": "ABCD"
"created_date": "23rd May 2018 08:20"
"assigned_to": "None"
"pending_approval_with": "USER20"
"delegated_to": "USER0"

"task_number": 2455
"from_system": "ETS"
"ticket_name": "Visiting Card"
"category_id": 4
"status_id": 53
"created_for": "ABCD"
"created_date": "23rd May 2018 08:20"
"assigned_to": "None"
"pending_approval_with": ", USER0, USER21"
"delegated_to": "USER11"

"task_number": 2454
"from_system": "ETS"
"ticket_name": "Visiting Card"
"category_id": 4
"status_id": 53
"created_for": "ABCD"
"created_date": "23rd May 2018 08:20"
"assigned_to": "None"
"pending_approval_with": ", USER0, USER21"
"delegated_to": "USER21"

"task_number": 2453
"from_system": "ETS"
"ticket_name": "Visiting Card"
"category_id": 4
"status_id": 53
"created_for": "ABCD"
"created_date": "23rd May 2018 08:20"
"assigned_to": "None"
"pending_approval_with": ", USER0"
"delegated_to": ""

"task_number": 2452
"from_system": "ETS"
"ticket_name": "Visiting Card"
"category_id": 4
"status_id": 54
"created_for": "ABCD"
"created_date": "23rd May 2018 08:20"
"assigned_to": "None"
"pending_approval_with": ", USER0"
"delegated_to": ""

"task_number": 2451
"from_system": "ETS"
"ticket_name": "Visiting Card"
"category_id": 4
"status_id": 53
"created_for": "ABCD"
"created_date": "23rd May 2018 08:20"
"assigned_to": "None"
"pending_approval_with": "USER0"
"delegated_to": ", USER14"

"task_number": 2450
"from_system": "ETS"
"ticket_name": "Visiting Card"
"category_id": 4
"status_id": 54
"created_for": "ABCD"
"created_date": "23rd May 2018 08:20"
"assigned_to": "None"
"pending_approval_with": "USER0"
"delegated_to": ""
>     # userName = 'USER0'
>     likeusername = ", " + userName
>     myticketdet = mycol.find({'$or':[{'pending_approval_with': userName, 'delegated_to': userName, 'pending_approval_with':{'$regex':
> likeusername}}]},{'$and':{'staus_id':53}}, {'_id':0})

我想使用python搜索USER0待处理的任务,上面是我编写的要搜索的代码,但它给我错误

TypeError:skip必须是int的实例// Werkzeug调试器

找不到确切的解决方案

0 个答案:

没有答案