mongodb - Mongodb query starts with inside $in Query
问题描述
I want to write an $in
query if column path starts with "/v1/user/1" or "/v1/user/2" then I want to select that particular document.
The sample document is as below:
{
"_id" : ObjectId("5f8872b486aa9e79d71d9809"),
"method" : "get",
"path" : "/v1/user/1/details/"
}
I tried to create a query but getting syntax error because of "/"
db.user.find({ "path": { $in: [ /^/v1/user/1/ , /^/v1/user/2/ ] } })
Could some one please help how to write the query.
解决方案
Your query was almost correct. You just missed to escape the /
. Try below query.
db.user.find({ "path": { $in: [ /^\/v1\/user\/1/ , /^\/v1\/user\/2/ ] } })
推荐阅读
- javascript - 带有php和mysql的图表js上x轴上的多个变量
- c# - 使用 FullTrustProcessLauncher 在 UWP 中添加环境变量
- c++ - 如何创建使用 CreateDefaultSubobject() 但允许子类更改子对象类型的 UE4 UCLASS 基类?
- c# - .net MVC 重定向与 JWT 令牌
- c# - 子类 C# 中的子类
- python - pyspark 中的 df 看起来不缩进
- wordpress - Woocommerce 结帐 - 添加复选框以显示/隐藏其他复选框
- xml - XmlDocument 未正确解析 xml 字符串
- combinations - 选择序列的子集以使它们的总和具有最小方差?
- javascript - Framework 7 + Vue 3 智能选择显示动态选择选项