0

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?

1 Answer 1

1

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('/');
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.