apoc.mongodb.update
Procedure APOC Full Deprecated
apoc.mongodb.update(host-or-key,db,collection,query,update) - updates the given documents from the mongodb collection and returns the number of affected documents
Signature
apoc.mongodb.update(host :: STRING?, db :: STRING?, collection :: STRING?, query :: MAP?, update :: MAP?) :: (value :: INTEGER?)
Input parameters
Name | Type | Default |
---|---|---|
host |
STRING? |
null |
db |
STRING? |
null |
collection |
STRING? |
null |
query |
MAP? |
null |
update |
MAP? |
null |
Install Dependencies
The Mongo procedures have dependencies on a client library that is not included in the APOC Library.
This dependency is included in apoc-mongodb-dependencies-4.1.0.11.jar, which can be downloaded from the releases page.
Once that file is downloaded, it should be placed in the plugins
directory and the Neo4j Server restarted.
Usage Examples
The examples in this section are based on a Mongo DB instance with a pre-populate twitter dataset. You can find instructions for setting this up at github.com/neo4j-examples/mongo-example.
We’re going to update the retweet_count
for the document with an id
of 591999465512382500
.
We can check its current value, by running the following query using apoc.mongodb.find.
CALL apoc.mongodb.find('mongodb://mongo:neo4j@mongo:27017', 'test', 'tweets', {id: 591999465512382500.0}, null, null)
YIELD value
RETURN value._id, value.text, value.retweet_count
LIMIT 1;
value._id | value.text | value.retweet_count |
---|---|---|
"553bbecae8f1e57878b72a1e" |
"[CALENDAR] Barça have 5 league games left, 2 #UCL semi-final games, and the Spanish Cup final: http://t.co/mWKOzNEWFo http://t.co/cyN1ZZNsSx" |
95.0 |
We can update that field, by running the following query:
CALL apoc.mongodb.update('mongodb://mongo:neo4j@mongo:27017', 'test', 'tweets', {id: 591999465512382500.0}, {`$set`:{retweet_count:96.0}});
value |
---|
1 |
And now let’s query it again:
CALL apoc.mongodb.find('mongodb://mongo:neo4j@mongo:27017', 'test', 'tweets', {id: 591999465512382500.0}, null, null)
YIELD value
RETURN value._id, value.text, value.retweet_count
LIMIT 1;
value._id | value.text | value.retweet_count |
---|---|---|
"553bbecae8f1e57878b72a1e" |
"[CALENDAR] Barça have 5 league games left, 2 #UCL semi-final games, and the Spanish Cup final: http://t.co/mWKOzNEWFo http://t.co/cyN1ZZNsSx" |
96.0 |