S
S
Stanislav Katasonov2014-08-26 12:59:31
JavaScript
Stanislav Katasonov, 2014-08-26 12:59:31

Automatic update of many-to-many relationships in MongoDB (Mongoose) ?

There are two data models with a many-to-many relationship, how to correctly implement a change in relationships when updating 1 model?

var User = new mongoose.Schema({
  venue: {
    type: [mongoose.Schema.Types.ObjectId],
    ref: 'Site'
  }
}

var Site = new mongoose.Schema({
  user: {
    type: [mongoose.Schema.Types.ObjectId],
    ref: 'User'
  }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2016-07-14
@alexey-m-ukolov

You have at least some nonsense with the syntax. If you format your code, you get something very strange:

bot.on('message', httpGet(msg))

httpGet(
  function(msg) {
    var chatId = msg.chat.id;
    console.log(msg);
    bot.sendMessage(chatId, "Привет11", {
      caption: "I'm a bot!"
    });
    return chatId;
  }.then(sendM(chatId), function(chatId) {
    return chatId;
  })
);

What are you even trying to do?

S
Sergey Krasnodemsky, 2014-08-26
@Prognosticator

Search by ref and update the record(s) of the second model when the first one changes. There is a mongoose-relationship
plugin for mongoose IMHO, using mongoose with its schemas is not justified in most cases.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question