What you show is not self-consistent.
If you really have two documents that you specified, your remove command will delete two documents, not one.
db.TextDocuments.insert({ 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", }]})
WriteResult({ "nInserted" : 1 })
db.TextDocuments.insert({ 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", }]})
WriteResult({ "nInserted" : 1 })
db.TextDocuments.remove({"name":"doc2"})
WriteResult({ "nRemoved" : 2 })
Now try the contents of your JS file (after reinstalling the same two documents, of course):
var db = connect ( "localhost: 27017/so" );
: localhost: 27017/so
var names = [ "doc1" , "doc2" ];
( = 0;
, , ( , , "doc1" .
"doc1" "doc2" script:
db.TextDocuments.insert({ name:"doc1", 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", }]})
WriteResult({ "nInserted" : 1 })
db.TextDocuments.insert({ 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", }]})
WriteResult({ "nInserted" : 1 })
var db = connect("localhost:27017/so");
connecting to: localhost:27017/so
for(i=0;i<names.length;i++){ print("Removing name " + names[i]); printjson(db['TextDocuments'].remove({"name":names[i]})); }
Removing name doc1
{ "nRemoved" : 1 }
Removing name doc2
{ "nRemoved" : 1 }