Test empty string in mongodb and pymongo

前端 未结 3 1517
闹比i
闹比i 2020-12-15 03:26

Here is my data structure.

[{
\"name\": \"David\",
\"lastname\": \"\",
},
{
\"name\": \"Angela\"
}]

\"lastname\" is sometimes present and

3条回答
  •  春和景丽
    2020-12-15 04:24

    You can use a regex query:

    db.test.find({ "lastname": /(.|\s)*\S(.|\s)*/ })

    This regex matches strings beginning or ending with 0 or N whitespaces (.|\s) and it have to be one or more non-whitespaces \S in the middle.

提交回复
热议问题