Here the models :
I want to do an update of "FirstLevel" from "Master" with the "prop" as search criteria.
{
"name": "Master",
"base": "PersistedModel",
"properties": {}
},
"validations": [],
"relations": {
"firstLevels": {
"type": "embedsMany",
"model": "FirstLevel"
}
},
"acls": [],
"methods": []
}
{
"name": "FirstLevel",
"base": "PersistedModel",
"properties": {
"prop": {
"type": "number"
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
With MongooseJS I can do it like this :
Master.update({'firstLevels.prop': 100},
{
$push: {
'firstLevels.$.prop2': 'test'
}
}, { upsert: true },
function (err) {
...
}
);
How can I do this with Loopback?
Fabien answered this question in the mailing list:
Loopback
currently doesn't provide native MongoDB
update commands like $push
and so forth, so your best bet would be to use the connector directly - like:
var mongodb = app.dataSources.db.connector;
mongodb.collection('Master').update( ... );