Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing array of objects to MongoDB #224

Open
csharsha opened this issue Nov 26, 2016 · 1 comment
Open

Passing array of objects to MongoDB #224

csharsha opened this issue Nov 26, 2016 · 1 comment

Comments

@csharsha
Copy link

csharsha commented Nov 26, 2016

Hi,

I have an Array of Objects with size of 81. It is as below

Array.length = 81
[1] Object {val: 1, candidates: Array[9]}

Like this I have 81 Objects. I am trying to pass this Array from EJS file hidden field to mongoose schema, but when I am trying to save this array it is getting saved as String in MongoDB, something like this
"[object Object],[object Object],[object Object],[object Object]............"

So I cannot evaluate this while I want to retrieve this data. Mongoose Schema is as below

var tbl_GameData = new mongoose.Schema({
     //id: {type: Number},
     LevelID : {type: Number},
     Data : {type: Array} 
   });

and saving from ejs file is like as below

app.post('/saveGame', function(req, res) {

           var gameData = new database.GameData({
         LevelID : 1,
         Data : req.body.gameData
});

gameData.save(function(err) {
   if(err){
   	console.log(err);
   }
   
   req.login(gameData, function(err){
   	if(err){
   		req.redirect('/login');
   	}
   	else {
   		res.render('startGame',{ user: req.user ,title:"Sudoku Online Match"});
   	}
    });
   
   });
   });

I dont know how to save this in DB so that I can retrieve it back as an array. Can you please help!

@mde
Copy link
Collaborator

mde commented Nov 26, 2016

This version of EJS is no longer maintained. The current version (installable by NPM) is here: https://github.com/mde/ejs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants