我正在使用RoboMongo删除许多与查询匹配的文档。但是,它表示没有删除任何文件,具体如下:
db.getCollection('assets').remove( { "source": "red" } );
但是,这非常有效:
db.getCollection('assets').find( { "source": "red" } );
并显示源“红色”的所有记录。
是否有任何理由不删除记录并且robomongo只输出0?
亲切的问候,
你是否正在使用副本集运行?如果是这样,请确保在主节点上运行remove命令。
你可以尝试这个:
db.assets.remove( {source : "red" } )
您可以尝试以下查询:
db.assets.remove( { "source":"red"} )
DeleteMany
为我工作:https://docs.mongodb.com/v3.2/reference/method/db.collection.deleteMany/#db.collection.deleteMany
db.getCollection('assets').deleteMany({source: 'red'})
这应该回来了
/* 1 */
{
"acknowledged" : true,
"deletedCount" : number // which is the number of documents deleted
}
从上面的查询中,我删除了快照ID为5c749daee3a0ec00047ffd5c
的所有乘客