简体   繁体   中英

how to delete this like array object using java3.2 driver with mongoDb

I want to delete an array element whose userId is ankit_12345@socityApp using java driver 3.2 (update is not working for me I want to use 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
    }

Try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM