al6x / mongo-model Goto Github PK
View Code? Open in Web Editor NEWModel for MongoDB (Node.JS)
Home Page: https://al6x.github.io/mongo-model
Model for MongoDB (Node.JS)
Home Page: https://al6x.github.io/mongo-model
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.
I had trouble running this without CoffeeScript, and I couldn't quite figure out the API from the documentation.
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
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
Hi,
I like the lib, but not sure if it's still maintained?
How does mongo-model compare to https://github.com/alexeypetrushin/mongo-lite?
Cheers,
Tadek
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
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!
Very cool little ORM you got here - I respect your choice not to roll validations into core. Have you checked this out? https://github.com/chriso/node-validator Works a treat!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.