消息关闭
    暂无新消息!

db.test.insert({
    "confData":[
     {
        "name":"blkIcon",
       "value":""
     },{
        "name":"111111",
       "value":""
     },{
        "name":"blkIcon",
       "value":""
     }
   ]
})
db.test.insert({
    "confData":[
     {
        "name":"blkIcon",
       "value":""
     },{
        "name":"2222222",
       "value":""
     },{
        "name":"blkIcon",
       "value":""
     }
   ]
})
db.test.insert({
    "confData":[
     {
        "name":"3333333333",
       "value":""
     },{
        "name":"blkIcon",
       "value":""
     }
   ]
})

db.test.insert({
    "confData":[
    {
        "name":"blkIcon",
       "value":""
     }
   ]
})

怎样去掉confData.name存在blkIcon重复的数据,第一条和第二条就需要去掉一个name=blkIcon的

2个回答

︿ 0
db.test.find().forEach( 
 function(row) {
  var disarr =  db.test.distinct( 'confData', { _id: row._id } )
  db.test.update( { _id: row._id }, {$set: {confData: disarr}})
 }
 )