apoc.mongodb.delete
Procedure APOC Full Deprecated
apoc.mongodb.delete(host-or-key,db,collection,query) - delete the given documents from the mongodb collection and returns the number of affected documents
Signature
apoc.mongodb.delete(host :: STRING?, db :: STRING?, collection :: STRING?, query :: MAP?) :: (value :: INTEGER?)
Input parameters
Name | Type | Default |
---|---|---|
host |
STRING? |
null |
db |
STRING? |
null |
collection |
STRING? |
null |
query |
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 delete the document with an id
of 591999465512382500
.
We can check it exists, 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;
value |
---|
{possibly_sensitive_appealable: FALSE, extended_entities: {media: [{display_url: "pic.twitter.com/cyN1ZZNsSx", indices: [118.0, 140.0], sizes: {small: {h: 507.0, resize: "fit", w: 296.0}, medium: {h: 507.0, resize: "fit", w: 296.0}, large: {h: 507.0, resize: "fit", w: 296.0}, thumb: {h: 150.0, resize: "crop", w: 150.0}}, id_str: "591999465080295424", expanded_url: "http://twitter.com/FCBarcelona/status/591999465512382464/photo/1", media_url_https: "https://pbs.twimg.com/media/CDc0YH9VEAA-h7I.png", id: 5.9199946508029542E17, type: "photo", media_url: "http://pbs.twimg.com/media/CDc0YH9VEAA-h7I.png", url: "http://t.co/cyN1ZZNsSx"}]}, in_reply_to_status_id_str: NULL, in_reply_to_status_id: NULL, created_at: "Sat Apr 25 16:17:26 +0000 2015", in_reply_to_user_id_str: NULL, source: "<a href=\"http://www.hootsuite.com\" rel=\"nofollow\">Hootsuite</a>", retweet_count: 96.0, retweeted: FALSE, geo: NULL, in_reply_to_screen_name: NULL, id_str: "591999465512382464", in_reply_to_user_id: NULL, favorite_count: 82.0, id: 5.9199946551238246E17, text: "[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", place: NULL, lang: "fr", favorited: FALSE, possibly_sensitive: FALSE, coordinates: NULL, truncated: FALSE, entities: {urls: [{expanded_url: "http://ow.ly/M6RsY", display_url: "ow.ly/M6RsY", indices: [95.0, 117.0], url: "http://t.co/mWKOzNEWFo"}], media: [{display_url: "pic.twitter.com/cyN1ZZNsSx", indices: [118.0, 140.0], sizes: {small: {h: 507.0, resize: "fit", w: 296.0}, medium: {h: 507.0, resize: "fit", w: 296.0}, large: {h: 507.0, resize: "fit", w: 296.0}, thumb: {h: 150.0, resize: "crop", w: 150.0}}, id_str: "591999465080295424", expanded_url: "http://twitter.com/FCBarcelona/status/591999465512382464/photo/1", media_url_https: "https://pbs.twimg.com/media/CDc0YH9VEAA-h7I.png", id: 5.9199946508029542E17, type: "photo", media_url: "http://pbs.twimg.com/media/CDc0YH9VEAA-h7I.png", url: "http://t.co/cyN1ZZNsSx"}], hashtags: [{indices: [45.0, 49.0], text: "UCL"}], user_mentions: [], symbols: []}, _id: "553bbecae8f1e57878b72a1e", contributors: NULL, user: {utc_offset: 7200.0, friends_count: 52.0, profile_image_url_https: "https://pbs.twimg.com/profile_images/562256323253788673/-j8H-E87_normal.jpeg", profile_background_image_url: "http://pbs.twimg.com/profile_background_images/533286076765306881/Bh7wB5M8.jpeg", listed_count: 26154.0, default_profile_image: FALSE, favourites_count: 21.0, is_translator: FALSE, created_at: "Tue Dec 15 09:53:50 +0000 2009", description: "Official account. Also follow us at @fcbarcelona_cat, @fcbarcelona_es, @fcbarcelona_br, @fcbarcelona_jap @fcbarcelona_id, @fcbarcelona_ara, @fcbarcelona_fra", profile_background_image_url_https: "https://pbs.twimg.com/profile_background_images/533286076765306881/Bh7wB5M8.jpeg", protected: FALSE, screen_name: "FCBarcelona", id_str: "96951800", profile_link_color: "9B0034", is_translation_enabled: TRUE, geo_enabled: FALSE, id: 9.69518E7, profile_background_color: "000000", lang: "en", profile_sidebar_border_color: "FFFFFF", profile_location: NULL, profile_text_color: "333333", verified: TRUE, profile_image_url: "http://pbs.twimg.com/profile_images/562256323253788673/-j8H-E87_normal.jpeg", time_zone: "Paris", url: "http://t.co/tLKuK0LXBC", contributors_enabled: FALSE, profile_background_tile: FALSE, profile_banner_url: "https://pbs.twimg.com/profile_banners/96951800/1427297556", entities: {description: {urls: []}, url: {urls: [{expanded_url: "http://www.fcbarcelona.com", display_url: "fcbarcelona.com", indices: [0.0, 22.0], url: "http://t.co/tLKuK0LXBC"}]}}, statuses_count: 61196.0, follow_request_sent: FALSE, profile_use_background_image: FALSE, followers_count: 1.4798695E7, default_profile: FALSE, following: TRUE, name: "FC Barcelona", profile_sidebar_fill_color: "CBC9C4", location: "Barcelona", notifications: FALSE}} |
Now let’s delete the document, by running the following query:
CALL apoc.mongodb.delete('mongodb://mongo:neo4j@mongo:27017', 'test', 'tweets', {id: 591999465512382500.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 |
---|