from everything i've read, this should be pretty easy (and maybe a web
browser and jquery would do better than curl). however, i am obviously
missing something because i just can't figure this out.

my test is:
curl -ik -X POST -d
'data={"url":"http://www.something.com","title":"something","note":"will
spaces work"}' https://localhost:8000/table

the handler:
   app.post('/table', function(req, res) {
      console.log("req.body.data: " + req.body.data);
      console.log("JSON.stringify(req.body.data): " +
JSON.stringify(req.body.data));
      db.saveNote(JSON.stringify(req.body.data), function(err, data) {
         res.send(data);
      } );
   } );

db.saveNote is:
   saveNote: function (input, callback) {
      var newNote = new Note( {
         data: {
            url : input.url,
            title : input.title,
            note : input.note,
         }
      } );

      newNote.save(function (err) {
         if (err) { console.log(err); callback(err); }
         callback(null, input.data);
      } );
   }

the model:
var NoteSchema = new Schema({
      _user    : { type: Schema.ObjectId, ref: 'User' },
      date     : { type: Date, default: Date.now },
      data     : {
         url      : { type: Url },
         title    : { type: String },
         note     : { type: String },
      },
      change   : [ Change ],
});

from mongo shell, i get records with Date.now but no data:
> db.notes.find();
{ "_id" : ObjectId("4f77f8eff96e915529000001"), "change" : [ ], "date"
: ISODate("2012-04-01T06:42:55.545Z") }
{ "_id" : ObjectId("4f77f9f2754bd55a29000001"), "change" : [ ], "date"
: ISODate("2012-04-01T06:47:13.940Z") }
{ "_id" : ObjectId("4f7801235069cebf29000001"), "change" : [ ], "date"
: ISODate("2012-04-01T07:17:54.820Z") }
{ "_id" : ObjectId("4f78134500f8f2632a000001"), "change" : [ ], "date"
: ISODate("2012-04-01T08:35:17.257Z") }
......

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to