Is there a MongoDB client side use case?

1,951 views
Skip to first unread message

Zoom

unread,
Aug 28, 2013, 2:50:40 AM8/28/13
to mongod...@googlegroups.com
I'm just looking through the "MongoDB Applied Design Patterns" book by Rick Copeland for a use case close to mine. After scanning the book I'm still left wondering how to use MongoDB in a client side app that can also work offline. 

For my painting type of app I'd like the JSON/BSON document to be local, while it is being edited with the interactive editing tools. The client side graphic renderer would then make queries on a client side document that is the schema for a painting and render the section of the document that is within the viewport. The apps custom hit detection solution would then find what document area was hit by a pointer, etc.

From what I'm reading I'm keen on the online server side uses of MongoDB for many concerns but I'm not sure about how to work with the main paint documents locally during editing without having to send constant queries to a server, which will slow down the interactive tools to much, plus force users to be online all the time.

Any links to a similar use case or advice is most appreciated.


Zoom

unread,
Aug 29, 2013, 1:15:54 AM8/29/13
to mongod...@googlegroups.com
Is this the right place to ask a MongoDB related question? 

All I want is some practical insight into how one would use MongoDB in a client side app, lets say something built with AngularJS. 

I want to hang on to specific documents returned by a MongoDB query and continue to edit them locally when the app is offline. When the app goes online the documents would update on the server end.

Is Mongoose useful for this?

Thanks for any feedback to get me seeing how MongoDB can work with an app that does local editing on documents and can be offline.

Zoom

unread,
Aug 29, 2013, 2:05:23 AM8/29/13
to mongod...@googlegroups.com
Is there something like PouchDB (a syncing IndexDB wrapper) available for MongoDB? 

Aaron Heckmann

unread,
Aug 29, 2013, 10:31:33 AM8/29/13
to mongod...@googlegroups.com
Sort of depends what client your thinking about. Mongoose could help you when coupled with one of the Angular plugins: http://plugins.mongoosejs.com/?q=angular
I have no idea if Angular supports offline.

Another option is http://www.meteor.com/ but
I'm not sure it supports offline either.

You'll at the very least need some API running
somewhere to which your client lib makes requests
for documents. Not sure which client libs
support offline these days but as long as it
detects when it's back online and syncs back
to your API (probably the tricky part) you
should be good. The trick may be planning a write
strategy, since multiple clients could be editing
the same document and go off/online at various
times.


--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb
 
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


--

Zoom

unread,
Aug 29, 2013, 9:47:57 PM8/29/13
to mongod...@googlegroups.com
Thanks for this, great to see the support for AngularJS.

Slowly after some research it is becoming clear that Mongoose is an alternate driver build on the native driver for MongoDB. What would be super helpful to me is to see some example of nodeJS plus Mongoose being used from a client side app (a hybrid style app, not just a browser based web app). While AngularJS is client side I would like to learn more about the basics before involving AngularJS.

For my most critical model/document I will need it to be on the local client for editing. For sync, having the user initiate a save operation or to trigger it at given points in the code transparently is good enough. I really just want to store documents in MongoDB, do CRUD operations against that, then return Mongoose model objects that my clint side app can work with and then flush back to MongoDB later (does not have to be real-time).

Is this doable?

See also the IRC channel -- freenode.net#mongodb
 
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Aaron Heckmann

unread,
Aug 30, 2013, 11:38:32 AM8/30/13
to mongod...@googlegroups.com
sounds doable. I've never used angular myself but you can find out how to use it here: http://angularjs.org/ and read the docs on the mongoose plugins to see how they work as well.

I encourage you to take meteor.com for a spin as well since its designed for use cases similar to yours and focuses on developer ease of use.



See also the IRC channel -- freenode.net#mongodb
 
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Zoom

unread,
Aug 30, 2013, 5:15:50 PM8/30/13
to mongod...@googlegroups.com
Coming from a Java background to HTML5 then Hybrid Apps has proven to be very interesting. I liked Solr and now it looks like MongoDB can fill those shoes well. It has taken time to transition from a application point of view to a NodeJS and Web App and then Hybrid App understanding. It is wonderful that a backend NodeJS based stack can then be connected to from a local development instance of NodeJS or a remote deployment instance of NodeJS, just by switching the connection URL.

From here I'm looking into finding the best way to use the Mongoose driver to query for documents/models that are suitable for working with on the client side app. My app makes extensive use of JSON configurations. Some configuration documents/models represent instructions that once loaded into the app are used to tell some process function in the app how to behave. Using these rule based configurations allows the process function to be repurposed. Other configuration documents/models represent the main data structure for the painting that the app is designed to produce, this means that once retrieved from MongoDB these document/models are edited then at some point that is not so real-time sync critical they are serialized back to MongoDB.

My main question now is how to hold onto selective documents/models retrieved from MongoDB? Are these Mongoose models like regular JS objects that can have dynamic properties added, removed, updated? To be performant and also work offline a given set of these document/model types need to be present on the client app for the kind of editing the app provides. Also, when the app exits a snapshot configuration would be stored in MongoDB so that when the app starts again the last in use and stored documents/models would be resolved and automatically reloaded. Has anyone wrestled with holding onto documents/models in a editing and reloading scenario?

Aaron Heckmann

unread,
Aug 30, 2013, 11:01:32 PM8/30/13
to mongod...@googlegroups.com
By client do you mean something like Firefox? I'm going to proceed to answer assuming yes.

Mongoose runs within nodejs only, not on a client like Firefox. This means none of the helpers you get with mongoose will do you any good on the client. Up to you if you still like it for the app layer or want to stick with plain js objects by using the node-mongodb-native driver directly instead.

On the client, again I'm thinking about browsers, you'll inevitably end up using JSON.parse() on the json received from your app server. There are many ways to store state on clients, I'm not gonna get into that here. But at any time you could have the client pass json back to your server, JSON.parse() it and hand it off to the driver for storage in mongodb.

Last note, mongoose documents are not plain js objects so tacking random key/val pairs on them will not work as you expect meaning they won't be saved. If you have completely unpredictable documents you'll probably want to skip mongoose, though there are some work around for that too using mongoose Mixed types.

--

Zoom

unread,
Aug 31, 2013, 2:32:08 AM8/31/13
to mongod...@googlegroups.com
Ah, thanks for this clarification.

My meaning of client is any web browser, Chrome, Firefox, etc, or a Webview browser component that something like Phonegap wraps into a Hybrid App that acts like a stand alone app. In the end its just some HTML, CSS for the UI and JS modules with their respective objects, no matter what kind of browser on what kind of device it runs on.

Your reply answered what I was getting at, thanks for confirming this fuzziness. As I was suspecting, I can just use the native MongoDB driver then use JSON.parse and JSON.stringify to manage the de/serialization on the client. I was just not sure where MongoDB left off and other functions began. Of course this means I will also have to use my own functions with no help from MongoDB for the editing of the deserialized objects, at least for some of the documents that need to be directly on the client and also work offline. Am I right?

Another option might be Firebase? It apparently uses MongoDB as a backend and then provides all local cache to remote store syncing in real-time, very powerful. Its just that I do not need that for most of my document types. Have you looked at Firebase?

To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Aaron Heckmann

unread,
Aug 31, 2013, 10:18:52 AM8/31/13
to mongod...@googlegroups.com
firebase looks straightforward. a bit spendy though.

Zoom

unread,
Sep 1, 2013, 3:17:39 AM9/1/13
to mongod...@googlegroups.com
I've been thinking it would be great to have a combo of Mongo and Firebase for sometime. What do you know, I found the following :-)

Reply all
Reply to author
Forward
0 new messages