Comments (7)
So I understand the result.
The expectation would be the o
would get sent to the fixture-loader and all the o.families
would need to be inserted into mongo and their _ids returned and embedded into the references defined within the o.people
. So essentially clients are defining these tree structures in a data-fixture file and mongoose-fixture is then deciphering the collections and handling all the embedded documents in a more literate form?
from mongoose-fixture.
I am not sure that mongo would need to be touched while the o
object is being created. Surely references are simply two properties that have the same value, regardless of whether they are in the same or different collections? The _id
properties' ObjectId
values can be created before o
is processed by mongoose-fixtures.
The snippet above is a working example of what would be passed to mongoose-fixture. The only difficulty would be how the section of BaseFixtureLoader.js
that I patched the other day would differentiate between an object of documents and an object of collections.
A possible solution could be to check the existence of a specific property, as follows.
if(_.isPlainObject(globalFixtureData)){
if(globalFixtureData.fixtureCollection){
// handle each property as a collection whose properties contain documents
}
if(globalFixtureData.dataFixtures){
fixtureSet = globalFixtureData.dataFixtures;
} else {
globalFixtureData = _.values(globalFixtureData);
}
}
if(_.isArray(globalFixtureData)){
fixtureSet = globalFixtureData;
}
However, there may be a much more elegant way of doing it.
from mongoose-fixture.
your right wouldn't need to touch mongo. just thinking of a case where you generate these _ids and then during the insertion phase something goes wrong and then you have these _ids with no match. Where inserting into mongo would give you some assurance that the fk-doc-ids exist. Maybe that isn't a concern and ideally that shouldn't/wouldn't happen. so yeah the implementation provided looks easy enough.
how would the --reset
or --remove
methods work? edit the way the mongoose-config works to accept multiple collections names to drop from?
from mongoose-fixture.
This scenario isn't really intended for fixtures that reference data that already exists in the db. For that, I think your approach (that I linked to above) would be better.
Here, any references must exist in the object. If they don't, javascript will inherently throw an error. I don't think there needs to be any special logic or error checking to handle this.
from mongoose-fixture.
Devising a way to integrate this into the fixtures user interface may be trickier. Could you just build the whole o
object and then only process the collections specified by the `fixtureConfig.fixtureListings config?
from mongoose-fixture.
Think that would be the tricky part.
I'm not opposed to supporting this interface, I could see it being useful for some to simplify their fixtures. I of course have my own use cases at the moment and need to get some changes for schema/model loading for a 0.3.0 release which will break apis for people. Why I'm incrementing off the 0.2.x line.
Anyways, if you want to put in the effort to implement this interface and write the test then I'm willing to merge it. If you build it from the 0.2.3 tag I'll help port it to the 0.3.0 version. I hope to have 0.3.0 out in the next day or so.
from mongoose-fixture.
When I said "trickier", I just meant, to make the decision. As long as the behaviour is documented, I don't think it would cause a problem.
I've realised that other projects use a similar type of interface
https://github.com/tdegrunt/mongodb-fixtures/blob/master/fixtures/wines.json
Pow fixtures also uses something similar but, when I tried it, it didn't work as documented.
from mongoose-fixture.
Related Issues (20)
- Cluster support for mongodb HOT 20
- fixture itemName/collection name must be same? HOT 4
- Improve CLI HOT 1
- Review the current interface for fixture loading within an app
- Auto generate data-fixtures using the defined mongo-database
- Improve CLI interface or Mongoose-Config to support node-conf for DEV, QA, PROD mongo connections
- Versioning for Mongoose Schemas
- Error for duplicate models from config
- Zealous Exception handling during (reset || remove)
- Update Data Fixtures
- Fixture Helper Service
- Unable to create fixture-listings with model dependencies not in loading scope
- How to add a data fixture for GridFS? HOT 4
- Difference in schema between mongoose and mongoose fixture HOT 2
- MissingSchemaError: Schema hasn't been registered for model "Product". HOT 7
- TypeError: Cannot call method 'create' of undefined
- Getting 'Arguments to path.resolve must be strings' for every command HOT 5
- Add an example that uses mongodb references HOT 16
- Improve comment added to generated fixture file / boilerplate HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongoose-fixture.