I have a collection TextDocuments
/* 0 */
{
name:"doc2",
pages:[{
pageNumber:"1",
text:"This is first page text",
},{
pageNumber:"2",
text:"This is second page text",
},{
pageNumber:"3",
text:"This is third page text",
}]
}
/* 1 */
{
name:"doc2",
pages:[{
pageNumber:"1",
text:"This is first page text",
},{
pageNumber:"2",
text:"This is second page text",
},{
pageNumber:"3",
text:"This is third page text",
}]
}
I want to remove documents from collection TextDocuments which has name = doc2 when Am running following query in mongo shell
rohitkumar@ubuntuhost:~$ mongo
> use mydb
switched to db mydb
> db.TextDocuments.remove({"name":"doc2"})
WriteResult({ "nRemoved" : 1 })
>
But in second scenario I have created a shell script
//File name collectionRemove.js
var db = connect("localhost:27017/mydb");
var names= ["doc1","doc2"];
for(i=0;i<names.length;i++){
db['TextDocuments'].remove({"name":names[i]});
}
when executing this from mongo shell using below command
rohitkumar@ubuntuhost:~$mongo mydb --eval "load('collectionRemove.js')"
documents are not getting removed. Any solution?