node.js - Create a new document using MEAN mongoose -


i'm new mongoose , mongodb, i'm trying create new document inside collection. i'm able update existing 1 or document collection. need create new document based on collection (i have single collection now). - createmoment function.

var mongoose = require('mongoose'); var db = mongoose.connect('mongodb://url , pass'); var usersschema  = require('./users_schema').usersschema; mongoose.model('usersm', usersschema); var usersaction;  mongoose.connection.once('open',function(){   var users = this.model('usersm');   var query = users.find();   query.where('userid');    query.exec(function(err, docs){     usersaction = docs;     console.log("docs: " + usersaction);     return usersaction;   });  });  exports.getdata = function(){   return usersaction; };  exports.createmoment = function(_fn, _ln, _conc,_lan,_lat,cb){   var users = mongoose.model('usersm');   console.log("createmoment called");   users.insertone({         'leadrank':1,         'adminapproval':true,         'userfname':_fn,         'userlname':_ln,         "conclusion":_conc,         'tentcoor':{'latitude' : _lat, 'longitude' : _lan}     }, null, function(err, result) {         assert.equal(err, null);         console.log("inserted document users collection.");         cb(result);     }); }; 

my schema: i'm not passing of fields yet

var mongoose = require('mongoose'); var schema = mongoose.schema;  var usersschema = new schema({   campname: {type:string, required:true},   centercoor: [{     latitude:{type:number},     longitude:{type:number}   }], zoom: {type:string}, users: [{   leadrank: {type:number},   adminapproval: boolean,   userfname: {type:string, required:true},   userlname: {type:string, required:true},   conclusion: {type:string},   tentcoor: [{     latitude:{type:number},     longitude:{type:number}   }] }] }, {collection: 'camps'}); exports.usersschema = usersschema; 


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -