繁体   English   中英

使用PHP以逗号分隔的输入值在MongoDB中搜索逗号分隔值

[英]Search comma separated values in MongoDB using PHP with comma separated input values

如何使用PHP以逗号分隔的输入值在MongoDB中搜索逗号分隔值?

例如:在collection1中,我用逗号分隔存储值,现在我想用逗号分隔的值搜索该列:

{service_list: 'a, b, c'}

现在我想用(a,d,e)搜索该字段。

如果我们存储在数组中,我们可以轻松搜索,但没有机会更改数据库结构。 我该如何解决这个问题?

你可以使用$regex

<?php

$m = new MongoClient();
$db = $m->selectDB('test');
$collection = new MongoCollection($db, 'phpmanual');

$cursor = $collection->find(
 array('service_list' => array('$regex' => 'something'))
);

?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM