Posts

Showing posts with the label MongooseJS

AngularJs & MongooseJS

 If MongoDB, then use MongooseJS (http://mongoosejs.com/) Advantages of Mongoose over usual MongoDB wrapper:  1. MongoDB uses named collections of arbitrary objects, and a Mongoose JS Model abstracts away this layer. Because of this, we don t have to deal with tasks such as asynchronously telling MongoDB to switch to that collection, or work with the annoying createFromHexString function.  2. Mongoose Models handle the grunt work of setting default values and validating data.  3. Mongoose lets us attach functions to our models  4. Mongoose handles limited sub-document population using manual references (i.e. no MongoDB DBRefs), which gives us the ability to mimic a familiar SQL join. Ways to use Mongoose correctly: 1) 1 Schema = 1 file 2) Mongoose can t handle multi-level population yet, and populated fields are not Documents. Nesting schemas is helpful but it s an incomplete solution. Design your schemas accordingly.   3) Declare your models exactly once a...