Automatically updating a record using count() of another collection
2
votes
3
answers
1459
views
I have been looking at the docs and searching for videos on my problem, but I find nothing. I have a db called
The problem is that when I insert another record to scripts, the data on
HPDASH
where I have 2 collections, scripts
and serverList
. My problem is that I want to create a field for serverList
that has the count()
of the collection scripts
.
I have tried this: db.scripts.insert([{name: 'local_script'}, {name: 'qidsloader'}])
db.serverList.insert({script_count: db.scripts.count() })
The problem is that when I insert another record to scripts, the data on
scripts_count
stays as 2.
Is it possible to achieve this on MongoDB?
Asked by sampjr
(21 rep)
Jul 28, 2017, 09:13 PM
Last activity: Jul 3, 2025, 04:09 PM
Last activity: Jul 3, 2025, 04:09 PM