String to String[]
Because a lot of data is migrated from mysql, there are fields like '123,456'
On the mysql side, you can use the find_in_set() function to query. I haven’t found a similar one on the mongodb side. I just thought that I could convert this into a string array, and then I could add an index to it.
db.dev_mc.update(
{"_id": 82839}, #匹配条件
[
{$set:{mcUid:{$split: ["$mcUid", ","]}}}
],
{ multi: true })
#全表修改就是
db.dev_mc.update(
{},
[
{$set:{mcUid:{$split: ["$mcUid", ","]}}}
],
{ multi: true })
2. split cutting display
db.getCollection("dev_mc").aggregate([{
$project: {
"mcUid": "$mcUid",
"split": {$split: ["$mcUid", ","]}
}
}])