Database Structure for Node.JS Image Tagging
I'm going to be creating a system with Node.js where I can tag images with tags I create (Eg: summer, school, beach, etc).
I have created a tagging system before with PHP and MySQL, the standard three table system (an Images table, tags_assoc, and tags table), but now that I'm trying this with Node.js I was wondering if there was a better way, perhaps with a NoSQL solution.
I would like to be able to do these things with the database:
- View in date order
- Search by tags (single tag, multiple tags, without a specifi开发者_开发技巧c tag)
You could absolutely use a nosql DB. How you would end up persisting depends entirely on which nosql DB you choose though. However, you could create your model similar to the following and use your db client/api to store the doc:
var Image = function() {
return {
url: '',
tags: [],
createDate: new Date()
};
}
var image = new Image();
image.url = '/images/day_at_the_beach.jpg',
image.tags.push('summer');
// persist to db
As far as retrieving the data, again the exact implementation is dependent on the DB you're using, but you can easily do both of the things you want. For example, in CouchDB, you'd set up views using map/reduce, or with MongoDB, you could use the mongoose client and build appropriate queries.
Edit: With mongoose, you'd also have to set up a mongoose.Schema before persisting and reading.
精彩评论