Reputation: 439
I have Schema:
var someSchema = new Schema({
data: {
nickname: {type: String},
id: Schema.Types.ObjectId,
message: { type: String},
},
createdAt: { type: Date, default: Date.now }
});
But when I am trying to use it:
some.collection.insert({data.nickname: nickname, data.message: message,}, function (err, doc) {
if (err) {
console.log("Something wrong !");
}
res.redirect('/');
});
I have an error: SyntaxError: Unexpected token .
How to insert data to my Object?
Upvotes: 0
Views: 696
Reputation: 311865
You need to use the same nested object syntax when defining the document to insert:
some.collection.insert({data: {nickname: nickname, message: message}}, function(err, doc) {
if (err) {
console.log("Something wrong !");
}
res.redirect('/');
});
Upvotes: 1