Removing a Mongo Database Collection in Meteor

Is there a way to drop the Mongo database collection from server side JavaScript code using Meteor? (really drop it all, not just Meteor.Collection.remove({});its contents)

Also, is there a way to remove Meteor.Collection from server side JavaScript code without dropping the corresponding database collection?

What for?

  • Search in subdocuments (subdocuments of a user document, for example userdoc.mailbox[12345]) with an underline or similar type as slow (for example, for large mailboxes).
  • On the other hand, placing all messages (in the context of the mailbox example) of all users in one large database, and then searching * all messages for one or several specific messages are very, very slow (for many users with large mailboxes).
  • There is also a size limit for Mongo documents, so if I save all user messages in his / her user document, the maximum mailbox size is <16 MB along with all other user data.

So, I want to have a database for each of my users in order to use it as a mailbox, then the maximum size for one message is 16 MB (very acceptable), and I can search for a mailbox using mango queries.

Furthemore, since I use Meteor, it would be nice if this mongo db collection was loaded as Meteor.Collection whenever a user logs in. When a user deactivates his account, db should, of course, be if the user just logs out, only Meteor.Collection should be discarded (and restored when you log in again).

To some extent, I got this job already, each user has his own db for the mailbox, but if someone cancels his / her account, I must delete this specific Mongolian collection manually. Also, I keep all the mongo db collections all the time, like Meteor.Collections, because I can't quit them.

This is a well-functioning server-side code snippet for one-collection mailboxes for each user:

var mailboxes = {};

Meteor.users.find({}, {fields: {_id: 1}}).forEach(function(user) {
    mailboxes[user._id] = new Meteor.Collection("Mailbox_" + user._id);
});

Meteor.publish("myMailbox", function(_query,_options) {
    if (this.userId) {
        return mailboxes[this.userId].find(_query, _options);
    };
});

:

myMailbox = new Meteor.Collection("Mailbox_"+Meteor.userId());
Deps.autorun(function(){
    var filter=Session.get("mailboxFilter");
    if(_.isObject(filter) && filter.query && filter.options)
        Meteor.subscribe("myMailbox",filter.query,filter.options);
});

, "mailboxFilter", , minimongo.

, , , - db-.

!

* "" , . .

+4
3

, , :

myMailbox.rawCollection().drop();

, , .

+6

myMailbox myMailbox._dropCollection(), .

, , , ,

+3

...

? , ?

, , . , , .

db

, NoSQL ( ) . (, , , ) .

, - ( , Twitter Yahoo) , : " N ". - . , .

, , , . , , , .

+1

All Articles