通过(Sails JS)水线将值推入mongodb数据库数组 [英] Push values into array of mongodb database through (sails js) waterline
本文介绍了通过(Sails JS)水线将值推入mongodb数据库数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
node js,sails js,waterline. 插入
node js,sails js,waterline. I need to update(or push) values into the below schema after insert
我正在将Sailsjs与水线和mongodb一起使用.
I am using sailsjs with waterline and mongodb.
{
"countries": {
"states": [
{
"statename": "state",
"districts": [
{
"distname": "district",
"cities": [
{
"cityname": "Hyderabad",
"places": [
{
"placename": "hitechcity"
}
]
}
]
}
]
}
]
}
}
我需要知道如何更新它,更新后我需要类似的东西
I need to know how to update it i need something like this after update
{
"countries": {
"states": [
{
"statename": "state",
"districts": [
{
"distname": "district",
"cities": [
{
"cityname": "Hyderabad",
"places": [
{
"placename": "hitechcity"
},
{
"placename": "someother place"
}
]
}
]
}
]
}
]
}
}
请有人帮助我.
推荐答案
好问题!您将要使用addToCollection()
:
await User.addToCollection(23, 'roles')
.members([3, 5, 6]);
在手机上完成操作,对任何错别字表示抱歉:)
Done on my phone so sorry about any typos :)
于2018年8月7日编辑,以反映Sails v1中的最佳实践.更多信息: https://sailsjs.com/documentation/reference /waterline-orm/models/add-to-collection
这篇关于通过(Sails JS)水线将值推入mongodb数据库数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文