apoc.mongodb.first

Procedure APOC Full Deprecated

apoc.mongodb.first(host-or-key,db,collection,query,[compatibleValues=false|true],[extractReferences=false|true],[objectIdAsMap=true|false]) yield value - perform a first operation on mongodb collection

Signature

apoc.mongodb.first(host :: STRING?, db :: STRING?, collection :: STRING?, query :: MAP?, compatibleValues = true :: BOOLEAN?, extractReferences = false :: BOOLEAN?, objectIdAsMap = true :: BOOLEAN?) :: (value :: MAP?)

Input parameters

Name Type Default

host

STRING?

null

db

STRING?

null

collection

STRING?

null

query

MAP?

null

compatibleValues

BOOLEAN?

true

extractReferences

BOOLEAN?

false

objectIdAsMap

BOOLEAN?

true

Output parameters

Name Type

value

MAP?

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.2.0.4.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.

Cypher
CALL apoc.mongodb.first('mongodb://mongo:neo4j@mongo:27017', 'test', 'tweets', {})
YIELD value
RETURN value;
Table 1. Results
value

{possibly_sensitive_appealable: FALSE, in_reply_to_status_id_str: NULL, in_reply_to_status_id: NULL, created_at: "Sat Apr 25 16:19:03 +0000 2015", in_reply_to_user_id_str: NULL, source: "<a href=\"http://ameanmagazine.blogspot.com\" rel=\"nofollow\">A Mean Magazine Bot</a>", retweeted_status: {possibly_sensitive_appealable: FALSE, in_reply_to_status_id_str: NULL, in_reply_to_status_id: NULL, in_reply_to_user_id_str: NULL, created_at: "Sat Apr 25 16:19:01 +0000 2015", source: "<a href=\"http://ifttt.com\" rel=\"nofollow\">IFTTT</a>", retweet_count: 1.0, retweeted: FALSE, geo: NULL, in_reply_to_screen_name: NULL, id_str: "591999864562655232", in_reply_to_user_id: NULL, favorite_count: 0.0, text: "RT: http://t.co/tgxDJSOrHb #webinar #TrueTwit #TechTip. A Node.js API development webinar: https://t.co/nBjkk4MnuN", place: NULL, id: 5.9199986456265523E17, lang: "en", favorited: FALSE, possibly_sensitive: FALSE, coordinates: NULL, truncated: FALSE, entities: {urls: [{expanded_url: "http://ift.tt/1brKQNC", display_url: "ift.tt/1brKQNC", indices: [4.0, 26.0], url: "http://t.co/tgxDJSOrHb"}, {expanded_url: "https://strongloop.com/node-js/node-js-webinar-series/", display_url: "strongloop.com/node-js/node-j…", indices: [91.0, 114.0], url: "https://t.co/nBjkk4MnuN"}], hashtags: [{indices: [27.0, 35.0], text: "webinar"}, {indices: [36.0, 45.0], text: "TrueTwit"}, {indices: [46.0, 54.0], text: "TechTip"}], user_mentions: [], symbols: []}, contributors: NULL, user: {utc_offset: NULL, friends_count: 8.0, profile_image_url_https: "https://pbs.twimg.com/profile_images/1238925920/logo_color_twitter_normal.png", profile_background_image_url: "http://pbs.twimg.com/profile_background_images/558932945889533952/6F0HO93x.jpeg", listed_count: 1442.0, default_profile_image: FALSE, favourites_count: 595.0, created_at: "Thu Aug 19 18:34:03 +0000 2010", is_translator: FALSE, description: "http://t.co/l4dBH8blSB (launching soon) posts and promote webinars from around the world, follow us for instant updates. We will invite you when launched.", profile_background_image_url_https: "https://pbs.twimg.com/profile_background_images/558932945889533952/6F0HO93x.jpeg", protected: FALSE, screen_name: "webinara", id_str: "180473434", profile_link_color: "1E667C", is_translation_enabled: FALSE, id: 1.80473434E8, geo_enabled: FALSE, profile_background_color: "8D9FA8", lang: "en", profile_sidebar_border_color: "C0DEED", profile_location: NULL, profile_text_color: "333333", verified: FALSE, profile_image_url: "http://pbs.twimg.com/profile_images/1238925920/logo_color_twitter_normal.png", time_zone: NULL, url: "http://t.co/l4dBH8blSB", contributors_enabled: FALSE, profile_background_tile: FALSE, profile_banner_url: "https://pbs.twimg.com/profile_banners/180473434/1422095245", entities: {description: {urls: [{expanded_url: "http://www.webinara.com", display_url: "webinara.com", indices: [0.0, 22.0], url: "http://t.co/l4dBH8blSB"}]}, url: {urls: [{expanded_url: "http://www.webinara.com", display_url: "webinara.com", indices: [0.0, 22.0], url: "http://t.co/l4dBH8blSB"}]}}, statuses_count: 176504.0, follow_request_sent: FALSE, default_profile: FALSE, profile_use_background_image: TRUE, following: FALSE, followers_count: 920.0, name: "webinara", profile_sidebar_fill_color: "DDEEF6", location: "Worldwide", notifications: FALSE}}, retweet_count: 1.0, retweeted: FALSE, geo: NULL, in_reply_to_screen_name: NULL, id_str: "591999874540904448", in_reply_to_user_id: NULL, favorite_count: 0.0, id: 5.9199987454090445E17, text: "RT @webinara: RT: http://t.co/tgxDJSOrHb #webinar #TrueTwit #TechTip. A Node.js API development webinar: https://t.co/nBjkk4MnuN", place: NULL, lang: "en", favorited: FALSE, possibly_sensitive: FALSE, coordinates: NULL, truncated: FALSE, entities: {urls: [{expanded_url: "http://ift.tt/1brKQNC", display_url: "ift.tt/1brKQNC", indices: [18.0, 40.0], url: "http://t.co/tgxDJSOrHb"}, {expanded_url: "https://strongloop.com/node-js/node-js-webinar-series/", display_url: "strongloop.com/node-js/node-j…", indices: [105.0, 128.0], url: "https://t.co/nBjkk4MnuN"}], hashtags: [{indices: [41.0, 49.0], text: "webinar"}, {indices: [50.0, 59.0], text: "TrueTwit"}, {indices: [60.0, 68.0], text: "TechTip"}], user_mentions: [{name: "webinara", indices: [3.0, 12.0], id: 1.80473434E8, screen_name: "webinara", id_str: "180473434"}], symbols: []}, _id: {date: 1429978826000, machineIdentifier: 15266277, processIdentifier: 30840, counter: 12003868, time: 1429978826000, timestamp: 1429978826, timeSecond: 1429978826}, contributors: NULL, user: {utc_offset: NULL, friends_count: 1.0, profile_image_url_https: "https://pbs.twimg.com/profile_images/481334978161029120/iu3zZFEk_normal.png", profile_background_image_url: "http://abs.twimg.com/images/themes/theme1/bg.png", listed_count: 979.0, default_profile_image: FALSE, favourites_count: 93.0, description: "Non curated list of relevant tweets about the MEAN stack. For a curated one visit @ameanmagazine", is_translator: FALSE, created_at: "Tue Jun 24 07:14:01 +0000 2014", profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png", protected: FALSE, screen_name: "ameanmbot", profile_link_color: "0084B4", id_str: "2585287004", is_translation_enabled: FALSE, geo_enabled: FALSE, id: 2.585287004E9, profile_background_color: "C0DEED", lang: "en", profile_sidebar_border_color: "C0DEED", profile_location: NULL, profile_text_color: "333333", verified: FALSE, profile_image_url: "http://pbs.twimg.com/profile_images/481334978161029120/iu3zZFEk_normal.png", time_zone: NULL, url: "http://t.co/HUvLnC0qar", contributors_enabled: FALSE, profile_banner_url: "https://pbs.twimg.com/profile_banners/2585287004/1403594236", profile_background_tile: FALSE, entities: {description: {urls: []}, url: {urls: [{expanded_url: "http://www.ameanmagazine.com", display_url: "ameanmagazine.com", indices: [0.0, 22.0], url: "http://t.co/HUvLnC0qar"}]}}, follow_request_sent: FALSE, statuses_count: 197348.0, default_profile: TRUE, following: TRUE, profile_use_background_image: TRUE, followers_count: 1676.0, name: "Mean Magazine Bot", location: "", profile_sidebar_fill_color: "DDEEF6", notifications: FALSE}}