scttnlsn / backbone.io

Backbone.js sync via Socket.IO

Home Page:http://scttnlsn.github.io/backbone.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Examples of sessionStore and mongooseStore

jackp opened this issue · comments

Hi Scott,

Awesome library. I'm trying to get it all working in my project but am having some trouble getting the mongooseStore and sessionStore middleware working. Could you provide some examples that use them?

I'm trying to do two things:

  1. I have a User model which I will want to sync with my backend's sessionStore.
  2. All others models will sync directly with mongoose

Many thanks

Any reason this is closed? I'm looking for the same thing.

Check out some of the existing examples. You can really just replace the memory store with the Mongoose store (pass the mongooseStore function a Mongoose model). Something like:

var users = backboneio.createBackend();
users.use(backboneio.middleware.cookieParser());
users.use(backboneio.middleware.session({ store: sessions }));
users.use(backboneio.middleware.mongooseStore(User));

Thanks, I've managed to work it out. However, deleting a model doesn't seem to be working. I'm using this for the server side and the same version of the index.html in examples.

var express = require('express');
var backboneio = require('../lib/index');
var mongoose = require('mongoose');
mongoose.connect('localhost', 'test');

var app = express.createServer();
app.use(express.static(__dirname));

app.listen(3000);
console.log('http://localhost:3000/');

var schema = new mongoose.Schema({
    text: String
});

var Message = mongoose.model('message', schema);

var messages = backboneio.createBackend();
messages.use(backboneio.middleware.mongooseStore(Message));

backboneio.listen(app, { messages: messages });

If you're using MongoDB, make sure you have idAttribute: '_id' set in your client-side Backbone model.

Bingo. Thanks.