These are chat archives for Automattic/mongoose

28th
Sep 2016
Daniel Brown
@DannyBrown
Sep 28 2016 15:25 UTC

Hi @all

I'm using the following function, but never receiving a callback.

mongoose.connection.collections[collection].remove(function() { ... })

Does anyone have any experience with this or debugging steps?

Brandon Jones
@Blackbaud-BrandonJones
Sep 28 2016 15:30 UTC
So quick question about naming conventions with Mongoose Schemas. When setting a field with a reference. Is there a convention for that? (ie. _creator: {type: ObjectId ref: 'user'} ); is the _keyName a documented/community supported standard?
@DannyBrown try [collection].drop(func... instead? I know Model.remove() works, but I believe collection is a .drop(
Daniel Brown
@DannyBrown
Sep 28 2016 15:33 UTC
@Blackbaud-BrandonJones, that doesn't seem to be running my callback either.
I simplified the code down to this for debugging purposes:
    console.log('I am getting this far');
    mongoose.connection.collections['User'].drop(function(err) {
        console.log('I am not getting this far');
    });
Brandon Jones
@Blackbaud-BrandonJones
Sep 28 2016 15:35 UTC
is it dropping the collection? you could also drop the bracket notation for .notation. collections.users/Users (be sure you're collection name is correct)
@DannyBrown if you aren't setting the collection name manually in your schema I think it defaults to plural. So be sure you're writing in the correct collection name.
Daniel Brown
@DannyBrown
Sep 28 2016 15:42 UTC

@Blackbaud-BrandonJones Thanks for your help so far. :)

It isn't dropping the collection. I can still see it after a refresh in Robomongo.

    console.log('Getting this far');

    console.log(mongoose.connection.collections.User);
    mongoose.connection.collections.User.drop(function(err) {
        console.log('Not getting here');
    });

The collection name is definitely User. Implemented using the dot notation above I can log the user collection, so its certainly correct. Still no dice.

Daniel Brown
@DannyBrown
Sep 28 2016 15:50 UTC
Any further ideas?
Brandon Jones
@Blackbaud-BrandonJones
Sep 28 2016 15:55 UTC
http://stackoverflow.com/questions/32017894/how-do-you-add-a-collection-in-mongoose is about the closets I can get. maybe just make sure its not undefined or so? sorry that's about all I got.