Comments (5)
Also got question about backbone collections - cant see usage example. Looks like everything done via model and responses are arrays or I'm wrong?
(off topic, but cant find better places to put)
from backbone-mongo.
Connections are pooled across requests. We use the commander CLI and once our scripts are executed call process.exit(0) from the final callback.
If automatic closing after each request is needed, I'd need to discuss with my co-author about exposing a non-pooling approach and we would want to test the set up and tear down impact. If an explicit release mechanism is required, we'd need to add some sort of reference counting to the pooling.
How would you rate each of these three solutions in terms of priority or need for you?
PS: we also use Node's callback pattern (rather than jQuery-style objects) since it is much less verbose:
word.save(function(err, project) {
debugger;
console.log(err ? 'Oh no an error' : 'We're saved!');
});
from backbone-mongo.
As for fetching through collections, it is less useful with BackboneORM. You can find examples in the test: https://github.com/vidigami/backbone-orm/blob/master/test/generators/collection/sync.coffee
On the server, we typically just do model queries. In the browser, we tend to do is use model queries with Knockback's kb.CollectionObservable that auto-allocates a collection (a simplified example):
class MyViewModel
constructor: ->
@things = kb.collectionObservable({view_model: ThingViewModel})
Thing.find { /* query here */ }, (err, things) => @things.collection().reset(things or [])
from backbone-mongo.
- I presume ORM should take care of those kind of issues (by ORM I don't mean backbone-orm) so I'd prefer this work automatically and have configuration setting for pooling or closing after each request.
That's more mongo client performance issue which I'm not quite familiar with.
Hope this will be helpful for decision making. - Concerning collections I can tell that will need them and can't really see if Backbone supports that why ORM can't just use it and provide results in collections or at least let fetch data using collections and may be have it configurable since this is part of backbone.
from backbone-mongo.
- Makes sense. I'll need to look into the performance implications of this. I believe (but need to check) most database drivers pool connections.
- Collections work. You can add query parameters to a Backbone.Collection's url and when you call fetch, it behaves just like normal Backbone.js (behind the scenes it uses the Model). I think we've retained all of the Collection functionality, but just added the possibility to use Node-style callbacks. For example:
class Things extends Backbone.Collection
url: '/things' # or yourDynamicQueryFunction('/things')
model: Thing
sync: require('backbone-http').sync(Collection)
class MyViewModel
constructor: ->
@things = kb.collectionObservable(new Things(), {view_model: ThingViewModel})
@things.collection().fetch (err) =>
I was just trying to say that when we have been using BackboneORM, we tend to think in Model queries and use results in the form of arrays of models, individual models, JSON, attributes transformations ($values/$select) rather than collections. That's what drives the above pattern (we typically skip the extra boilerplate of defining a Collection)
from backbone-mongo.
Related Issues (15)
- toJSON doesn't serialize attached models HOT 1
- After an error emitted by mongo, queries do not return
- Fix intermittent test failures HOT 2
- Ids that look like numbers should not be parsed as if they are numbers HOT 1
- Should _rev be an optional feature?
- $unique does not work properly with $page
- Promise feature request HOT 2
- Frontpage example has error? HOT 1
- Nested attributes don't save and fetch as expected HOT 3
- Multiple calls to Model#set don't cause change triggers to fire HOT 4
- Can't have it working with node.js modules HOT 3
- Multiple calls to unset causes only the last attribute unset to be unset HOT 2
- Sorting by ids doesn't work HOT 2
- Browserify breaks with inflection 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 backbone-mongo.