I'm new with node.js and mongodb. In my database, I have several collections (one for users, one for article, and in the future one more...).
In my server.js file, I would like to be able to write in each of these collections. Here is the code I use, but I'm not able to access all my collections... Have you an ideas to make that possible?
var databaseUrl = "mydb"; // "username:password@example.com/mydb"
var collections = ["users", "article", "reports", "archery"]
var db = require("mongojs").connect(databaseUrl, collections);
Thank you
You don't have to know all of your collections in advance to use mongojs
, you can access a collection dynamically using db.collection('name_of_collection')
and use it just like an existing collection. This call will also cache it so that next time, you can say db.name_of_collection
.
There's a bunch of examples at their git hub page: https://github.com/gett/mongojs
Good luck.