0

I want to find out from the database by:

db.xx.find({"fields.name.sourceTexts":null})

or

db.xx.find({"fields.name.sourceTexts":""})

but it not work and find all

[
    {
        "_id": "5b432195e28b99127c59161e",
        "fields": {
            "img": {
                "sourceTexts": [],
                "_class": "us.codecraft.webmagic.selector.PlainText"
            },
            "name": {
                "sourceTexts": [],
                "_class": "us.codecraft.webmagic.selector.PlainText"
            },
            "old": {
                "sourceTexts": [],
                "_class": "us.codecraft.webmagic.selector.PlainText"
            },
            "post": {
                "sourceTexts": [],
                "_class": "us.codecraft.webmagic.selector.PlainText"
            },
            "focusTieba": [],
            "visitor": {
                "sum": 0,
                "list": []
            },
            "follow": {
                "sum": 0,
                "list": []
            },
            "fans": {
                "sum": 0,
                "list": []
            }
        },
        "request": {
            "url": "http://tieba.baidu.com/home/main?un=%DB%A2%D4%B495",
            "cookies": {},
            "headers": {},
            "priority": 0,
            "binaryContent": false
        },
        "skip": false,
        "_class": "us.codecraft.webmagic.ResultItems"
    }
]
djaszczurowski
  • 4,385
  • 1
  • 18
  • 28
funbean
  • 5
  • 4

2 Answers2

0

If I got what you need, I think you are in need of next query

db.xx.find({"fields.name.sourceTexts":[]})
damirljub
  • 307
  • 2
  • 9
  • thank answer , now i want delete {fields.name.sourceTexts:[]} , but i cant find by {fields.name.sourceTexts:[]} – funbean Jul 10 '18 at 06:46
  • You can find it but what you need is to delete by its MongoId. And you should use findOne(). https://docs.mongodb.com/manual/reference/method/db.collection.findOne/ – damirljub Jul 10 '18 at 07:05
  • but result has many , i want like sql `select * from table where name is null` like this – funbean Jul 10 '18 at 07:15
0

You can use $exists operator to check if field exists and $size operator to check if array is empty.

db.xx.find( { "fields.name.sourceTexts" : { $exists:true, $size:0 } } )