Test empty string in mongodb and pymongo

前端 未结 3 1529
闹比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:17

    Facing this problem I thought in another solution:

    db.collection.find({"lastname": {"$gte": " "}})
    

    With this I could get only the not empty strings, also ignoring null and not existent field, because any printable value (ASCII) has a greater value than space (32).

    https://en.wikipedia.org/wiki/ASCII

提交回复
热议问题