Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4001584
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:55:22+00:00 2026-05-20T07:55:22+00:00

Hey, I am Just Learning CoffeeScript and I Keep getting Errors. Here is my

  • 0

Hey, I am Just Learning CoffeeScript and I Keep getting Errors. Here is my code:

Db   = require('./lib/mongodb').Db
ObjectID = require('./lib/mongodb').ObjectID
Server   = require('./lib/mongodb').Server

class UserDataProvider
    constructor = (host,port)->
        this.db = new Db( 'test' , new Server(host ,port,{}))
    getCollection = (callback) ->
        this.db.collection 'data',(error,data)->
            if error then callback(error)
            else callback(data)
    findAll = (callback) ->
        this.getCollection (error,data)->
            if error then callback error
            else
                data.find (error, cursor) ->
                    if error then callback error
                    else
                        cursor.toArray (error, results)->
                            if error then callback error
                            else callback(null,results)
    findById = (id,callback)->
        this.getCollection (error, data)->
          if error then callback error
          else
            data.findOne { _id: id} , (error, result)->
              if error then callback error
              else callback(null, result)
    save = (data, callback)->
        this.getCollection (error, collection)->
            if error then callback error
            else
                if typeof(data.length) is "undefined"
                then data = [data]

                collection.insert data ()->
                    callback null, data

exports.UserDataProvider = UserDataProvider

When I try to use
userdataprovider.save( ?? BLAH BLAH BLAH ??) // I already instantiated it.

I get this error:

TypeError: Object #<UserDataProvider> has no method 'save'
    at Object.<anonymous> (/home/akshay/dev/statServer/app.js:8:15)
    at param (/usr/local/lib/node/.npm/connect/0.5.10/package/lib/connect/middleware/router.js:146:21)
    at param (/usr/local/lib/node/.npm/connect/0.5.10/package/lib/connect/middleware/router.js:157:15)
    at pass (/usr/local/lib/node/.npm/connect/0.5.10/package/lib/connect/middleware/router.js:162:10)
    at Object.router [as handle] (/usr/local/lib/node/.npm/connect/0.5.10/package/lib/connect/middleware/router.js:168:6)
    at next (/usr/local/lib/node/.npm/connect/0.5.10/package/lib/connect/index.js:218:15)
    at Object.handle (/usr/local/lib/node/.npm/express/1.0.7/package/lib/express/server.js:65:5)
    at next (/usr/local/lib/node/.npm/connect/0.5.10/package/lib/connect/index.js:218:15)
    at Server.handle (/usr/local/lib/node/.npm/connect/0.5.10/package/lib/connect/index.js:231:3)
    at Server.emit (events.js:45:17)

If it matters, I am using Expressjs and Nodejs with Native MongoDB Driver

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:55:23+00:00Added an answer on May 20, 2026 at 7:55 am

    The problem is that you’re using = instead of : to define instance-level methods.

    CoffeeScript’s class construct is an odd hybrid of object and function. Code within the class body runs immediately—for instance,

    class UserDataProvider
        a = 'foo'
        console.log a
    

    prints foo. But when you use the object syntax key: value, you define properties of the prototype (except in the case of the special keyword constructor):

    class UserDataProvider
      a: 'foo'
    
    (new UserDataProvider).a   # 'foo'
    

    This might seem odd, but it allows you to run one-time static initialization code which can be useful, including private variables that can only be seen by methods defined within the class:

    class UserDataProvider
        secretPassword = Math.random()
        getHash: -> hash(secretPassword)
    

    Long story short: Use : instead of = when defining instance properties. (For static properties, @a = b and @a: b are equivalent; both set UserDataProvider.a to b.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, just learning about composition of classes and ran into this error. Gradebook.h
Hey guys, I'm just starting out with GWT and am getting the following error
hey i just want to gather the locations in google maps database which are
Hey guys. Just like in the title - I'm having some problems doing it.
Hey all, so I'm just trying to make a basic chatbox on my site
Hey all when i use TOAD to update a table all works just fine
Hey, I just added a Widget to my Android App but when I now
After some hours creating a vb.net helper class for unit-tests and integrating moq into
I am writing this to get a more realistic view of what I should

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.