node.js - MongoDB how to use the result of find to save to another collection -


this mongoose schema:

var connectionschema = new schema({     users: [{         social_id : string,          name : string,          hair_color : string,          gender : string,          interested_in : [string],         current_look : {             photo_url : string,              identifier: {                 type : string,                  brand : string,                  color : string             }         }     }],     time : {type: date, "default": date.now} }); 

and doing this:

mongoose.model('connection', connectionschema); var connection = mongoose.model('connection'); var c = new connection({         "users": mynetwork.user_list}); 

where mynetwork result of findbyidandupdate call.

and when printing c getting this:

{              "_id": "53308c83b1cd1b081df7a7c4",             "time": "2014-03-24t19:50:27.915z",             "users": [                 {                     "_id": "533073ecb3ce5208062a8668",                     "interested_in": []                 },                 {                     "_id": "533073ecb3ce5208062a8668",                     "interested_in": []                 }             ]         } 

can me figure out doing wrong?

here listing works. have differences:

var mongoose = require('mongoose'); var schema = require('mongoose').schema;  var conn = mongoose.createconnection('mongodb://localhost');  var connectionschema = new schema({   users: [{     social_id: string,     name: string,     hair_color: string,     interested_in: [string],     current_look: {       photo_url: string,       identifier: {         type: string,         brand: string,         color: string       }     }   }],   time: { type: date, "default": date.now } });  var connection = conn.model( "connection", connectionschema );  conn.on('open', function() {    var c = new connection({     users:[{       "interested_in": [         "male",         "female"       ],       "current_look": {         "photo_url": "some url"       },       "social_id": "facebook:524934406",       "gender": "male",       "hair_color": "black",       "name": "faisal"     }]   });    console.log(    "created:\n===\n\n" +    json.stringify( c, undefined, 2  )   );    c.save(function(err,doc){     if (err) console.log(err);     console.log(       "saved:\n===\n\n" +       json.stringify( doc, undefined, 2 )     );   });   }); 

and produce output like:

created: ===  {   "_id": "5330cae8c3b89719766fb529",   "time": "2014-03-25t00:16:40.122z",   "users": [     {       "social_id": "facebook:524934406",       "hair_color": "black",       "name": "faisal",       "_id": "5330cae8c3b89719766fb52a",       "current_look": {         "photo_url": "some url"       },       "interested_in": [         "male",         "female"       ]     }   ] } saved: ===  {   "__v": 0,   "_id": "5330cae8c3b89719766fb529",   "time": "2014-03-25t00:16:40.122z",   "users": [     {       "social_id": "facebook:524934406",       "hair_color": "black",       "name": "faisal",       "_id": "5330cae8c3b89719766fb52a",       "current_look": {         "photo_url": "some url"       },       "interested_in": [         "male",         "female"       ]     }   ] } 

compare code have or doing spot differences.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -