MongoDb query array with null values

后端 未结 3 1325
旧巷少年郎
旧巷少年郎 2021-02-20 07:51

I have objects in my collection that look like:

{ MyArray:[null, \"some value\", null] }

I want to query those objects that have a null value a

3条回答
  •  無奈伤痛
    2021-02-20 08:02

    (not really an answer, but does not fit into a comment)

    I can not reproduce the problem, I copied your data to the mongo shell and tried in MongoDB versions 2.2.3, 2.4.1 and here in 2.4.0:

    MongoDB shell version: 2.4.0 connecting to: test

    > db.version()
    2.4.0
    > db.xxx.insert({
    ... "_id" : BinData(3,"ch9PrWveqU6niB6FGVhIOg=="),
    ... "PeerGroup" : "male",
    ... "ProductId" : BinData(3,"weRiKOtXEUSDZHkGHLcwzw=="),
    ... "CategoryIds" : [
    ... BinData(3,"BXzpwVQozECLaPkJy26t6Q=="),
    ... BinData(3,"ox303ZeM50KelvoUbPBJ8Q=="),
    ... BinData(3,"26ziaY+G9UKMyjmtVkkhcg=="),
    ... BinData(3,"D2X8vObte0eJHNcDfp2HBw==")
    ... ],
    ... "ShopId" : BinData(3,"ZdfPmrlKR0GkLPC4djJuKw=="),
    ... "BrandId" : BinData(3,"kCHyuyLvgECxPF1nxwr7qQ=="),
    ... "Created" : ISODate("2012-08-24T07:42:12.416Z"),
    ... "LastActivity" : ISODate("2013-01-14T19:38:11.776Z"),
    ... "Price" : 129.9,
    ... "Sale" : false,
    ... "Rating" : 11.057340703605368,
    ... "RatingTimed" : 0.05670431130054035,
    ... "Available" : null,
    ... "FreeDelivery" : null,
    ... "Attrs" : [
    ... null,
    ... null,
    ... null,
    ... null
    ... ]
    ... }
    ... )
    > db.xxx.find({"Attrs":null}).pretty()
    {
        "_id" : BinData(3,"ch9PrWveqU6niB6FGVhIOg=="),
        "PeerGroup" : "male",
        "ProductId" : BinData(3,"weRiKOtXEUSDZHkGHLcwzw=="),
        "CategoryIds" : [
            BinData(3,"BXzpwVQozECLaPkJy26t6Q=="),
            BinData(3,"ox303ZeM50KelvoUbPBJ8Q=="),
            BinData(3,"26ziaY+G9UKMyjmtVkkhcg=="),
            BinData(3,"D2X8vObte0eJHNcDfp2HBw==")
        ],
        "ShopId" : BinData(3,"ZdfPmrlKR0GkLPC4djJuKw=="),
        "BrandId" : BinData(3,"kCHyuyLvgECxPF1nxwr7qQ=="),
        "Created" : ISODate("2012-08-24T07:42:12.416Z"),
        "LastActivity" : ISODate("2013-01-14T19:38:11.776Z"),
        "Price" : 129.9,
        "Sale" : false,
        "Rating" : 11.057340703605368,
        "RatingTimed" : 0.05670431130054035,
        "Available" : null,
        "FreeDelivery" : null,
        "Attrs" : [
            null,
            null,
            null,
            null
        ]
    }
    

    Please, copy the above sequence to your mongo shell and post the results here.

提交回复
热议问题