pgherveou / mongoosefiller Goto Github PK
View Code? Open in Web Editor NEWdenormalization plugin for mongoose
denormalization plugin for mongoose
Hey man, awesome concept and could really help solve the natural headache of NoSQL solutions!
I'm trying to integrate this with my project, and the example collections are similar to the following:
var GearSchema = new mongoose.Schema({
name: { type: String }
});
var Gear = mongoose.model('Gear', GearSchema);
var BrandSchema = new mongoose.Schema({
name: { type: String }
});
var Brand = mongoose.model('Brand', BrandSchema);
...
Now assuming I have a couple brands in the brands collection like follows:
[{ name: 'Canon', _id: 1 }, { name: 'Nikon', _id: 2 }]
If I create a new Gear like so:
var gear = new Gear({ name: '5D Mark II', brand: { _id: 1 }});
gear.save();
...the gear will simply have brand populated with the _id as I passed it in, like this:
{ name: '5D Mark II', brand: { _id: 1 }}
If I then modify the associated brand/child item (like changing its name), the gear item finally gets populated correctly.
Am I missing something?
Thanks!
I'm not sure if any code updates are required to support 4.x but when I try to do an npm install
in an application that has 4.x installed I get the following error:
npm ERR! node v0.12.4
npm ERR! npm v2.10.1
npm ERR! code EPEERINVALID
npm ERR! peerinvalid The package mongoose does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants [email protected]
If lucky, updating the version in package.json may be all that is required.
May seem like a stupid question, but what's the syntax/method for filling multiple paths within a single model (from different sources)?
Thanks (again)!
Great plugin! Loving it. This not an issue, unless it's not possible, in which case it's a feature request. Had a quick question about updating embedded arrays...
Say you've got a standard User model, and the following:
var VoteSchema = mongoose.Schema({
vote : { type: Number }
});
var ItemSchema = mongoose.Schema({
text : { type: String, },
votes : [VoteSchema]
});
VoteSchema.plugin(filler, {
ref : 'User',
dest : 'Claim',
pos : 'votes.$.',
select : 'firstName lastName'
});
This works wonderfully (thanks again!), but it returns the user fields at the same level of 'vote'. So you get this...
votes = [
{ firstName: 'blah', lastName: 'blah', vote: 1 }
]
Is it possible to make it sync the user fields behind a 'user' key, like this:
votes = [
{ user: { firstName: 'blah', lastName: 'blah'}, vote: 1 }
]
Thanks for your help.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.