What is the format of the NodeBB entries in MongoDB?



  • Hi guys,

    I'm trying to read a NodeBB database in MongoDB using pymongo.
    I'm exploring it using Robomongo, but I am having trouble finding all the things I want.

    What I am struggling with at the moment is the "User" entry. The entry that associates a uid with the username. What is the tag I should use to look for the username? Or even better, how can I find out? What code should I be looking at?

    Thanks!



  • If you're new to Mongo (I am too) and thinking about the database in terms of a more traditional relational database, it can be pretty confusing.

    I would recommend MongoChef over Robomongo as your client.

    In the collection view, run a query like:

    { "username": { $not: { $exists: false } } }

    That will give you all the objects whose username field is populated. As far as I understand it, there is no users table, just objects. An object can be anything and the only thing which determines what it is, is the fields / properties on that object. If the username is populated, it will be a user.

    My database may be different to yours as I imported from a legacy forum but my user objects have an entry called _key which is set to a user ID. Hope that helps


  • Admin

    Every document in the database has a _key field that is indexed. You can get the document describing a user with simply

    db.objects.find({_key:"user:1"});

    For more info see https://github.com/NodeBB/NodeBB/wiki/Database-Structure



  • @codecowboy said in What is the format of the NodeBB entries in MongoDB?:

    If you're new to Mongo (I am too) and thinking about the database in terms of a more traditional relational database, it can be pretty confusing.

    I would recommend MongoChef over Robomongo as your client.

    I'll give it a try. Any particular reason?

    In the collection view, run a query like:

    { "username": { $not: { $exists: false } } }

    I've been doing this kind of thing for a while now (yes, I had to get used to it xD), but I don't understand why you would do it that way. Why not simply
    { "username": { $exists: true} } }
    ?

    That will give you all the objects whose username field is populated. As far as I understand it, there is no users table, just objects. An object can be anything and the only thing which determines what it is, is the fields / properties on that object. If the username is populated, it will be a user.

    My database may be different to yours as I imported from a legacy forum but my user objects have an entry called _key which is set to a user ID. Hope that helps

    Thanks :-)

    @baris said in What is the format of the NodeBB entries in MongoDB?:

    Every document in the database has a _key field that is indexed. You can get the document describing a user with simply

    db.objects.find({_key:"user:1"});

    For more info see https://github.com/NodeBB/NodeBB/wiki/Database-Structure

    Great, that wiki was exactly what I was looking for. I had managed to locate the posts by just playing with robomongo. This will make it easier... xD



  • @SgtBurden No good reason and I havent used Robomongo in a while. I just remember it being very confusing. Mongochef is similar enough to a mysql client not to freak me out ;) I did the query that way because I was just trying things out - your way makes more sense in this context :)


Log in to reply
 


Looks like your connection to NodeBB was lost, please wait while we try to reconnect.