Coder Social home page Coder Social logo

mongo-model's People

Contributors

al6x avatar wanbok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mongo-model's Issues

should support authenticate

I tried to use mongo-model in heroku.
But heroku need authenticate by using The mongodb URL scheme ( http://www.mongodb.org/display/DOCS/Connections )
which is not supported yet by mongo-model
it is mandatory to deploy mongo-model in heroku

following code is mongodb native code.

exports.connect = function(url, options, callback) {
...

  db.open(function(err, db){
    if(!err && authPart){
      db.authenticate(auth[0], auth[1], function(err, success){
        if(success){
          callback(null, db);
        }
        else {
          callback(err ? err : new Error('Could not authenticate user ' + auth[0]), null);
        }
      });
    } else {
      callback(err, db);
    }
  });
...

in mongo-model I think authenticate call should be some where near here.

driver/db.coffee

  open: (options..., callback) ->
    options = options[0] || {}
    throw new Error "callback required!" unless callback
    @nDb.open (err, nDb) =>
      callback err, @

I don't think mongo-model should support the mongodb URL scheme
but it should be configureable using Driver.configure.

I tried to modify mongo-model.
But in experimental branch you have modified a lot of code :). I couldn't understand how it works where to put authenticate code.

Changing database with driver.configure

Model = require 'mongo-model'
Driver = require 'mongo-model/lib/driver'
Fiber = require "fibers"

require 'mongo-model/lib/sync'

sync = ->

  Driver.configure
    databases:
      blog:
        name: 'blog_development'
      default:
        name: 'default_development'
        host: 'localhost'

  db = Model.db 'blog'
  db.clear()

  assert db.name, 'blog_development'

  db.close()

Fiber(sync).run()

global.assert = (args...) -> require('assert').deepEqual args...

Asset will fail, except if I use db = Driver.db 'blog' instead

model.save() throws TypeError: Undefined is not a function error

Anytime I save a model I get an error on crud.coffee (compiled the error is on line 26, coffeescript line 22). My code is pretty simple, gathered from the examples:

# test-model.coffee

Model = require 'mongo-model'

class Test extends Model
  @collection 'tests'

  constructor: () ->
    console.log "Ready, lets go"

module.exports = Test
> Test = require './test-model.coffee'
> test = new Test(message: "don't stop me now")
> test.save()

...

The model saves successfully into the database, but I receive this error immediately after save():

TypeError: undefined is not a function
    at /home/noazark/Desktop/node_modules/mongo-model/lib/model/crud.coffee:26:20
    at /home/noazark/Desktop/node_modules/mongo-model/lib/model/crud.coffee:186:22
    at /home/noazark/Desktop/node_modules/mongo-model/lib/model/crud.coffee:189:18
    at /home/noazark/Desktop/node_modules/mongo-model/lib/model/callbacks.coffee:32:18
    at Test.runCallbacks (/home/noazark/Desktop/node_modules/mongo-model/lib/model/callbacks.coffee:35:14)
    at Test._runCallbacksRecursively (/home/noazark/Desktop/node_modules/mongo-model/lib/model/crud.coffee:174:21)
    at /home/noazark/Desktop/node_modules/mongo-model/lib/model/crud.coffee:25:23
    at /home/noazark/Desktop/node_modules/mongo-model/lib/model/crud.coffee:186:22
    at /home/noazark/Desktop/node_modules/mongo-model/lib/model/crud.coffee:189:18
    at /home/noazark/Desktop/node_modules/mongo-model/lib/model/callbacks.coffee:32:18

Fiber not found in mongo-model/lib/helper.coffee

ReferenceError: Fiber is not defined
at Object.db (/Users/davem/project1/node_modules/mongo-model/lib/helper.coffee:89:39, :112:13)

This occurred despite npm install mongo-model

I found that I had to cd to the node_modules/mongo-model/ and run npm install manually from that directory

David

This document schema caught me by surprise

Hi Alexey, had some questions for you.

Given the following code:

  @thread = new Thread({name: "test-thread", thread_id: "my-thread-id"})
  @thread.messages.push new Message(sender_id: 1, receiver_id: 2, body: "woot")
  @thread.save -> console.log 'saved'

And when I run the following query from the Mongo shell:

  db.threads.findOne()

I see the following result:

  {
    "0" : {
        "name" : "test-thread",
        "thread_id" : "my-thread-id"
    },
    "messages" : [
        {
            "0" : {
                "sender_id" : 1,
                "receiver_id" : 2,
                "body" : "wot"
            },
            "_class" : "Message"
        }
    ],
    "_class" : "Thread",
    "_id" : "Cg4Np7"
  }

What surprised me is this bit:

    "0" : {
        "name" : "test-thread",
        "thread_id" : "my-thread-id"
    },

Can you help me understand why my attributes are embedded in a hash value with a key of 0? The same pattern exists in the embedded message too. I would normally expect the name and thread_id attributes to live one level up in the document.

I am also surprised at the value of the _id. Doesn't look like a standard mongo object ID. And correct me if I am wrong, but shouldn't the embedded messages also have an _id attribute? I'm new to mongo so I could be mistaken here.

I really like the mongo-model API, but the surprising document format has me scratching my head. Anyhow, thanks for the great work here and I look forward to having a viable alternative to Mongoose!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.