Could I remove doc by real collection name in Mongodb?


#1

I have like this

myCollection = new Mongo.Collection('my_collection');
myCollection.insert({...........});

// but I want to remove any doc by real name
my_collection.remove(.....);
// don't 
myCollection.remove(........); 

Please help me.


#2

myCollection is a collection object that refers to set of methods to access my_collection

if you want to remove a doc from that collection, you must use its .remove() method, which is only available via the collection object

Maybe if you told us why you want to do it that way, we could offer a solution.


#3

I create the Backup and Restore tool for my project.
So I want to remove any docs before Restore, but I would like to use the real collection name in Mongodb directly.
Ex: in Mongodb cmd: db.my_collection.remove…
Please help me.


#4

so myCollection._name ?


#5

Thanks for your reply.
I don’t want to get the collection name, I would like to use real collection name to access the Mongodb.


#6

use this


#7

Very thanks, look great :smiley: