如何使用带有mongoDb的java3.2驱动程序删除此类数组对象

时间:2016-06-03 17:16:50

标签: java mongodb

我想删除一个数组元素,其userId是ankit_12345 @ socityApp,使用java驱动程序3.2(更新不适合我,我想使用updateOne())

{ "_id" : { "$oid" : "57516ef3ba3dfb1bc8f35d2b"} ,
        "post" : 
        { "fileLocation" : "uri/mediaServer/position" ,
        "timestamp" : "Jun 3, 2016 5:20:11 PM" , 
        "title" : "ankit testing likes" ,
        "description" : "you can get food on low price" ,
        "userID" : "ankit_12345@socityApp" , 
        "userIP" : "192.168.1.22" ,
        "category" : 1 ,
        "likeCount" : -1 ,
        "commentCount" : 0 , 
        "likes" : { "userID" : "ankit_12345@socityApp" , "postID" : "57516ef3ba3dfb1bc8f35d2b" , "userName" : "ankit mishra"}
        } ,
        "location" : { "latitude" : -71.24342 , "longitude" : 71.24342} ,
        "priority" : 2
    }

1 个答案:

答案 0 :(得分:0)

试试这个:

db.collection.update({"post.userID":"ankit_12345@socityApp"},
                        { $set : {'yourArray': [] }} , {multi:true} );