mongodb - Mongoosejs can't query with findById -


i have meteor application saving stuff mongodb , have api wish make , expose via rest.

express = require 'express' mongoose = require 'mongoose'  app = express()  mongoose.connect process.env.mongo_url  account = mongoose.model 'users',     profile:         available: boolean  app.get "/accounts/meta/:account_id", (req, res) ->     account = account.findbyid req.params.account_id     , (error, account) ->         if account?             res.jsonp                 account: account         else             res.jsonp 404,                 error: "account not found"  app.listen 2000 

the problem can't query id's see in database. example have user:

{     "_id": "zcdshukr5dth3xhz5",     "createdat": 1373188729653,     "last_seen": 1373465529548,     "profile": {         .... 

if go /accounts/meta/zcdshukr5dth3xhz5 says 'cast objectid failed value "zcdshukr5dth3xhz5" @ path "_id"'. tried in every possible way query document without luck. ideas?

the problem need define schema model tell mongoose _id field string instead of standard objectid in collection:

accountschema = new mongoose.schema     _id: string     profile:         available: boolean account = mongoose.model 'users', accountschema 

Comments