Reputation: 1317
First time using mongodb. I am using node.js and mongojs on the server side. A little confused. The reversal of db.save is find, and I'd like to be able to do something similar to:
db.furni.find( db.furni_types.chair, db.furni_types.chair.plastic );
Current setup:
// Chair types
db.furni_types.save({ type: "chair", material: "wood" });
db.furni_types.save({ type: "chair", material: "plastic" });
db.furni_types.save({ type: "chair", material: "beanbag" });
// other furni types
db.furni_types.save({ type: "bed", material: "silk" });
db.furni_types.save({ type: "table", effect: "glass" });
db.furni.save({id: "13626450", name: "ComfyMan", type: "chair", material: "wood", description: "The most comfortable chair in extistence."});
A few questions:
Am I going about this the right way or what?
Would the array found in db.furni.save(type: "chair", material: "wood") sufficient if I wanted to use these as objects later?
What if I wanted to do something like:
db.furni.save( name: "Super Comfort", db.furni_types.chair, db.furni_types.chair.wood );
Would the above work?
Upvotes: 0
Views: 63
Reputation: 1891
This is definitely not the right way... First off it is very much a RDBMS way of thinking, (relational database...). Secondly if you want to be able to do something like this:
db.furni.find( db.furni_types.chair, db.furni_types.chair.plastic );
Then it would just be:
db.furni.find({type: "chair", material:"plastic"});
Note that what you are passing into find is an object, so you cannot just expect to pass strings or something from other variables in a comma separated format, let alone think that you can just reference your types model that way (db.furni_types != a direct accessor at the data in the database, its an interface upon which you have to "find").
So just looking at what you have posted and what I suggest, you will also see that if you have to type "chair" in both, and "plastic" in both regardless, what value do you expect to gain from your proposed approach?
Upvotes: 1