Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

What command do I use and run?

3 Answers

0 votes
by (106k points)

To create a MongoDB dump of my database you can use mongodump:

$ ./mongodump --host prod.example.com 

connected to: prod.example.com 

all dbs 

DATABASE: log to dump/log 

log.errors to dump/log/errors.bson 

713 objects 

log.analytics to dump/log/analytics.bson 

234810 objects 

DATABASE: blog to dump/blog 

blog.posts to dump/log/blog.posts.bson 

59 objects 

DATABASE: admin to dump/admin

0 votes
by (108k points)

For dumping your database for backup you call this command on your terminal

mongodump --db database_name --collection collection_name

And for importing your backup file to mongodb you can use the following command on your terminal

mongorestore --db database_name path_to_bson_file

0 votes
by (108k points)

With the right combination of $lookup, $project, and $match, you can join multiple tables on multiple parameters. You can join two collections in Mongo by using lookup which is offered in 3.2 version. In your case, the query would be

db.comments.aggregate({

    $lookup:{

        from:"users",

        localField:"uid",

        foreignField:"uid",

        as:"users_comments"

    }

})

or you can also join with respect to the users, refer the following commands:

db.users.aggregate({

    $lookup:{

        from:"comments",

        localField:"uid",

        foreignField:"uid",

        as:"users_comments"

    }

})

Related questions

0 votes
2 answers
0 votes
0 answers
0 votes
1 answer
0 votes
0 answers
0 votes
2 answers
asked Sep 9, 2019 in SQL by Sammy (47.6k points)

Browse Categories

...